Book Image

Mastering Data analysis with R

By : Gergely Daróczi
Book Image

Mastering Data analysis with R

By: Gergely Daróczi

Overview of this book

Table of Contents (19 chapters)
Mastering Data Analysis with R
Credits
www.PacktPub.com
Preface

Latent class models


Latent Class Analysis (LCA) is a method for identifying latent variables among polychromous outcome variables. It is similar to factor analysis, but can be used with discrete/categorical data. To this end, LCA is mostly used when analyzing surveys.

In this section, we are going to use the poLCA function from the poLCA package. It uses expectation-maximization and Newton-Raphson algorithms for finding the maximum likelihood for the parameters.

The poLCA function requires the data to be coded as integers starting from one or as a factor, otherwise it will produce an error message. To this end, let's transform some of the variables in the mtcars dataset to factors:

> factors <- c('cyl', 'vs', 'am', 'carb', 'gear')
> mtcars[, factors] <- lapply(mtcars[, factors], factor)

Tip

The preceding command will overwrite the mtcars dataset in your current R session. To revert to the original dataset for other examples, please delete this updated dataset from the session by...