The multiLCA
function in the multilevLCA
package estimates single- and multilevel measurement and structural latent class models. Moreover, the function performs two different strategies for model selection. Methodological details can be found in Bakk et al. (2022), Bakk and Kuha (2018), and Di Mari et al. (2023).
Different output visualization tools are available for all model specifications. See, e.g., plot.multiLCA
.
multiLCA(
data,
Y,
iT,
id_high = NULL,
iM = NULL,
Z = NULL,
Zh = NULL,
incomplete = FALSE,
fixedslopes = FALSE,
startval = NULL,
kmea = TRUE,
extout = FALSE,
dataout = TRUE,
sequential = TRUE,
numFreeCores = 2,
maxIter = 1e3,
tol = 1e-8,
reord = TRUE,
fixedpars = 1,
NRmaxit = 100,
NRtol = 1e-6,
verbose = TRUE
)
Single-level model estimation returns (if extout = FALSE
, a subset):
Class proportions
Response probabilities given the latent classes
Matrix of posterior class assignment (proportional assignment)
Matrix of posterior class assignment (modal assignment)
Vector of posterior class assignment (modal assignment)
Expected number of classification errors
Expected proportion of classification errors
Average of mClassErrProb
Entropy-based R\(^2\)
Bayesian Information Criterion (BIC)
Akaike Information Criterion (AIC)
Intercepts in logistic parametrization for class proportions
Intercepts in logistic parametrization for response probabilities
Vector of logistic parameters
Standard errors
Variance-covariance matrix
Number of iterations for EM algorithm
Difference between last two elements of log-likelihood sequence for EM algorithm
Full log-likelihood series for EM algorithm
Contributions to log-likelihood score
Model specification
Strategy for handling of eventual missing values
Final sample size for model estimation
Single-level model estimation with covariates returns (if extout = FALSE
, a subset):
Class proportions given the covariates
Sample average of mPi
Response probabilities given the latent classes
Matrix of posterior class assignment (proportional assignment)
Expected number of classification errors
Expected proportion of classification errors
Average of mClassErrProb
Entropy-based R\(^2\)
Bayesian Information Criterion (BIC)
Akaike Information Criterion (AIC)
Intercept and slope parameters in logistic models for conditional class membership
Intercepts in logistic parametrization for response probabilities
Vector of logistic parameters
Uncorrected standard errors
Corrected standard errors (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Corrected standard errors only for the gammas (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Cross-derivatives for asymptotic standard error correction in two-step estimation (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Uncorrected variance-covariance matrix
Corrected variance-covariance matrix (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Inverse of information matrix for structural model
Number of iterations for EM algorithm
Difference between last two elements of log-likelihood sequence for EM algorithm
Full log-likelihood series for EM algorithm
Model specification
Estimation approach for structural model
Strategy for handling of eventual missing values
Final sample size for model estimation
Multilevel model estimation returns (if extout = FALSE
, a subset):
Higher-level class proportions
Lower-level class proportions given the higher-level latent classes
Response probabilities given the lower-level latent classes
Posterior joint class assignment (proportional assignment)
Log of cPMX
Posterior lower-level class assignment given high-level class membership (proportional assignment)
Log of cPX
Posterior higher-level class assignment for lower-level units after marginalization over the lower-level classes (proportional assignment)
Posterior higher-level class assignment for higher-level units (proportional assignment)
Log of mPW
Posterior higher-level class assignment for lower-level units (proportional assignment)
Posterior lower-level class assignment for lower-level units after marginalization over the higher-level classes (proportional assignment)
Lower-level entropy-based R\(^2\)
Higher-level entropy-based R\(^2\)
Lower-level Bayesian Information Criterion (BIC)
Higher-level Bayesian Information Criterion (BIC)
Lower-level BIC-type approximation the integrated complete likelihood
Higher-level BIC-type approximation the integrated complete likelihood
Akaike Information Criterion (AIC)
Intercepts in logistic parametrization for higher-level class proportions
Intercepts in logistic parametrization for conditional lower-level class proportions
Intercepts in logistic parametrization for response probabilities
Vector of logistic parameters
Standard errors
Variance-covariance matrix
Expected information matrix
Number of iterations for EM algorithm
Difference between last two elements of log-likelihood sequence for EM algorithm
Full log-likelihood series for EM algorithm
Current log-likelihood for higher-level units
Contributions to log-likelihood score
Model specification
Strategy for handling of eventual missing values
Final sample size for model estimation
Multilevel model estimation with lower-level covariates returns (if extout = FALSE
, a subset):
Higher-level class proportions
Lower-level class proportions given the higher-level latent classes and the covariates
Sample average of mPi
Response probabilities given the lower-level latent classes
Posterior joint class assignment (proportional assignment)
Log of cPMX
Posterior lower-level class assignment given high-level class membership (proportional assignment)
Log of cPX
Posterior higher-level class assignment for lower-level units after marginalization over the lower-level classes (proportional assignment)
Posterior higher-level class assignment for higher-level units (proportional assignment)
Log of mPW
Posterior higher-level class assignment for lower-level units (proportional assignment)
Posterior lower-level class assignment for lower-level units after marginalization over the higher-level classes (proportional assignment)
Lower-level entropy-based R\(^2\)
Higher-level entropy-based R\(^2\)
Lower-level Bayesian Information Criterion (BIC)
Higher-level Bayesian Information Criterion (BIC)
Lower-level BIC-type approximation the integrated complete likelihood
Higher-level BIC-type approximation the integrated complete likelihood
Akaike Information Criterion (AIC)
Intercepts in logistic parametrization for higher-level class proportions
Intercept and slope parameters in logistic models for conditional lower-level class membership
Intercepts in logistic parametrization for response probabilities
Vector of logistic parameters
Uncorrected standard errors
Corrected standard errors (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Corrected standard errors only for the gammas (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Cross-derivatives for asymptotic standard error correction in two-step estimation (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Uncorrected variance-covariance matrix
Corrected variance-covariance matrix (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Expected information matrix
Expected information matrix only for the gammas
Inverse of information matrix for structural model
Number of iterations for EM algorithm
Difference between last two elements of log-likelihood sequence for EM algorithm
Full log-likelihood series for EM algorithm
Current log-likelihood for higher-level units
Contributions to log-likelihood score
Contributions to log-likelihood score only for the gammas
Model specification
Estimation approach for structural model
Strategy for handling of eventual missing values
Final sample size for model estimation
Multilevel model estimation with lower- and higher-level covariates returns (if extout = FALSE
, a subset):
Higher-level class proportions given the covariates
Higher-level class proportions averaged over higher-level units
Lower-level class proportions given the higher-level latent classes and the covariates
Sample average of mPi
Response probabilities given the lower-level latent classes
Posterior joint class assignment (proportional assignment)
Log of cPMX
Posterior lower-level class assignment given high-level class membership (proportional assignment)
Log of cPX
Posterior higher-level class assignment for lower-level units after marginalization over the lower-level classes (proportional assignment)
Posterior higher-level class assignment for higher-level units (proportional assignment)
Log of mPW
Posterior higher-level class assignment for lower-level units (proportional assignment)
Posterior lower-level class assignment for lower-level units after marginalization over the higher-level classes (proportional assignment)
Lower-level entropy-based R\(^2\)
Higher-level entropy-based R\(^2\)
Lower-level Bayesian Information Criterion (BIC)
Higher-level Bayesian Information Criterion (BIC)
Lower-level BIC-type approximation the integrated complete likelihood
Higher-level BIC-type approximation the integrated complete likelihood
Akaike Information Criterion (AIC)
Intercept and slope parameters in logistic models for conditional higher-level class membership
Intercept and slope parameters in logistic models for conditional lower-level class membership
Intercepts in logistic parametrization for response probabilities
Vector of logistic parameters
Uncorrected standard errors
Corrected standard errors (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Corrected standard errors only for the alphas (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Corrected standard errors only for the gammas (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Cross-derivatives for asymptotic standard error correction in two-step estimation (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Uncorrected variance-covariance matrix
Corrected variance-covariance matrix (see Bakk & Kuha, 2018; Di Mari et al., 2023)
Expected information matrix
Expected information matrix only for the alphas
Expected information matrix only for the gammas
Inverse of information matrix for structural model
Number of iterations for EM algorithm
Difference between last two elements of log-likelihood sequence for EM algorithm
Full log-likelihood series for EM algorithm
Current log-likelihood for higher-level units
Contributions to log-likelihood score
Contributions to log-likelihood score only for the alphas
Contributions to log-likelihood score only for the gammas
Model specification
Estimation approach for structural model
Strategy for handling of eventual missing values
Final sample size for model estimation
Input matrix or dataframe.
Names of data
columns with indicators.
Number of lower-level latent classes.
Name of data
column with higher-level id. Default: NULL
.
Number of higher-level latent classes. Default: NULL
.
Names of data
columns with lower-level covariates (non-numeric covariates are treated as nominal). Default: NULL
.
Names of data
columns with higher-level covariates (non-numeric covariates are treated as nominal). Default: NULL
.
Whether to estimate the model with missing values included by means of full-information maximum-likelihood estimation (TRUE
) or perform row-wise deletion of missing values (FALSE
). Default: FALSE
.
Whether to estimate multilevel models with covariates with fixed lower-level slope parameters across the higher-level classes by means of log-linear parametrization. Default: FALSE
.
Name of data
column with starting values for lower-level latent classes. Default: NULL
.
Whether to compute starting values for single-level model using \(K\)-means (TRUE
), which is recommended for algorithmic stability, or \(K\)-modes (FALSE
). Default: TRUE
.
Whether to output extensive model and estimation information. Default: FALSE
.
Whether to match class predictions to the observed data. Default: TRUE
.
Whether to perform sequential model selection (TRUE
) or parallelized model selection (FALSE
). Default: TRUE
.
If performing parallelized model selection, the number of CPU cores to keep free. Default: 2
.
Maximum number of iterations for EM algorithm. Default: 1e3
.
Tolerance for EM algorithm. Default: 1e-8
.
Whether to (re)order classes in decreasing order according to probability of scoring yes on all items. Default: TRUE
.
One-step estimator (0
), two-step estimator (1
) or two-stage estimator (2
). Default: 1
.
Maximum number of iterations for Newton-Raphson algorithm. Default: 100
.
Tolerance for Newton-Raphson algorithm. Default: 1e-6
.
Whether to print estimation progress. Default: TRUE
.
The indicator columns may be coded as as consecutive sequence of integers from 0, or as characters.
To directly estimate a latent class model, iT
and (optionally) iM
should be specified as a single positive integer. To perform model selection over range of consecutive positive integers as the number of latent classes, iT
and/or iM
may be specified in the form iT_min:iT_max
and/or iM_min:iM_max
. It is possible to specify iT = iT_min:iT_max
with either iM = NULL
or iM
equal to a single positive integer, iM = iM_min:iM_max
with iT
equal to a single positive integer, or iT = iT_min:iT_max
with iM = iM_min:iM_max
. All model selection procedures return the output of the optimal model based on the BIC.
In the case where both iT
and iM
are defined as a range of consecutive positive integers, model selection can be performed using the sequential three-stage approach (Lukociene et al., 2010) or a simultaneous approach. The sequential approach involves (first step) estimating iT_min:iT_max
single-level models and identifying the optimal alternative iT_opt1
based on the BIC, (second step) estimating iM_min:iM_max|iT = iT_opt1
multilevel models and identifying the optimal alternative iM_opt2
based on the higher-level BIC, and (third step) estimating iT_min:iT_max|iM = iM_opt2
multilevel models and identifying the optimal alternative iT_opt3
based on the lower-level BIC. The simultaneous approach involves devoting multiple CPU cores on the local machine to estimate all combinations in iT = iT_min:iT_max, iM = iM_min:iM_max
and identifying the optimal alternative based on the lower-level BIC.
Bakk, Z., & Kuha, J. (2018). Two-step estimation of models between latent classes and external variables. Psychometrika, 83, 871-892.
Bakk, Z., Di Mari, R., Oser, J., & Kuha, J. (2022). Two-stage multilevel latent class analysis with covariates in the presence of direct effects. Structural Equation Modeling: A Multidisciplinary Journal, 29(2), 267-277.
Di Mari, Bakk, Z., R., Oser, J., & Kuha, J. (2023). A two-step estimator for multilevel latent class analysis with covariates. Psychometrika.
Lukociene, O., Varriale, R., & Vermunt, J. K. (2010). The simultaneous decision(s) about the number of lower-and higher-level classes in multilevel latent class analysis. Sociological Methodology, 40(1), 247-283.
# \donttest{
# Use the artificial data set
data = dataTOY
# Define vector with names of columns with items
Y = colnames(data)[1+1:10]
# Define name of column with higher-level id
id_high = "id_high"
# Define vector with names of columns with lower-level covariates
Z = c("Z_low")
# Define vector with names of columns with higher-level covariates
Zh = c("Z_high")
# Single-level 3-class LC model with covariates
out = multiLCA(data, Y, 3, Z = Z, verbose = FALSE)
out
# Multilevel LC model
out = multiLCA(data, Y, 3, id_high, 2, verbose = FALSE)
out
# Multilevel LC model lower-level covariates
out = multiLCA(data, Y, 3, id_high, 2, Z, verbose = FALSE)
out
# Multilevel LC model lower- and higher-level covariates
out = multiLCA(data, Y, 3, id_high, 2, Z, Zh, verbose = FALSE)
out
# Model selection over single-level models with 1-3 classes
out = multiLCA(data, Y, 1:3, verbose = FALSE)
out
# Model selection over multilevel models with 1-3 lower-level classes and
# 2 higher-level classes
out = multiLCA(data, Y, 1:3, id_high, 2, verbose = FALSE)
out
# Model selection over multilevel models with 3 lower-level classes and
# 1-2 higher-level classes
out = multiLCA(data, Y, 3, id_high, 1:2, verbose = FALSE)
out
# Model selection over multilevel models with 1-3 lower-level classes and
# 1-2 higher-level classes using the default sequential approach
out = multiLCA(data, Y, 1:3, id_high, 1:2, verbose = FALSE)
out
# }
Run the code above in your browser using DataLab