A generic S3 extractor function designed to retrieve internal components from various model and simulation objects
produced by the LCPA package. This function provides a consistent interface across different classes,
allowing users to access estimated parameters, fit statistics, simulation truths, standard errors, and more.
extract(object, what, ...)# S3 method for LCA
extract(object, what, ...)
# S3 method for LPA
extract(object, what, ...)
# S3 method for LCPA
extract(object, what, ...)
# S3 method for LTA
extract(object, what, ...)
# S3 method for sim.LCA
extract(object, what, ...)
# S3 method for sim.LPA
extract(object, what, ...)
# S3 method for sim.LTA
extract(object, what, ...)
# S3 method for fit.index
extract(object, what, ...)
# S3 method for compare.model
extract(object, what, ...)
# S3 method for SE
extract(object, what, ...)
The requested component. Return type varies depending on what and the class of object.
If an invalid what is provided, an informative error is thrown listing valid options.
An object of one of the following classes:
LCA — Latent Class Analysis model results.
LPA — Latent Profile Analysis model results.
LCPA — Latent Class/Profile Analysis with covariates.
LTA — Latent Transition Analysis model results.
sim.LCA — Simulated LCA data with known truth.
sim.LPA — Simulated LPA data with known truth.
sim.LTA — Simulated LTA data with known truth.
get.fit.index — Model fit indices object.
compare.model — Model comparison results.
get.SE — Standard error estimation results.
A character string specifying the name of the component to extract.
Valid choices depend on the class of object. See Details section for full listings.
Additional arguments passed to methods (currently ignored).
extract(LCA): Extract fields from a LCA object
extract(LPA): Extract fields from a LPA object
extract(LCPA): Extract fields from a LCPA object
extract(LTA): Extract fields from a LTA object
extract(sim.LCA): Extract fields from a sim.LCA object
extract(sim.LPA): Extract fields from a sim.LPA object
extract(sim.LTA): Extract fields from a sim.LTA object
extract(fit.index): Extractor method for fit.index objects
extract(compare.model): Extract fields from a compare.model object
extract(SE): Extract fields from a SE object
For LCA, LPA, LCPA, and LTA objects, components reflect estimated parameters.
For sim.LCA, sim.LPA, and sim.LTA objects, components reflect true data-generating parameters.
In SE objects:
Top-level components like vcov and hessian are only available when method = "Obs".
Requesting them under Bootstrap triggers a warning and returns NULL.
Parameter-specific SEs (e.g., means, par) are stored within the se list.
You can extract them directly by name (e.g., extract(se_obj, "means")).
Attempting to extract unavailable parameter SEs (e.g., par from an LPA model) triggers an error with available options.
For fit.index and compare.model objects, valid components are dynamically determined from the object’s names.
All methods ignore additional arguments (...).
This function supports extraction from ten primary object classes. Below are available components for each:
LCALatent Class Analysis model results. Available components:
paramsList containing all estimated model parameters.
par3D array (\(L \times I \times K_{\max}\)) of conditional response probabilities.
P.ZVector of length \(L\) with latent class prior probabilities.
nparNumber of free parameters in the model.
Log.LikLog-likelihood of the final model.
AICAkaike Information Criterion.
BICBayesian Information Criterion.
best_BICBest BIC value across replication runs (if nrep > 1).
P.Z.Xn\(N \times L\) matrix of posterior class probabilities.
ZVector of length \(N\) with MAP-classified latent class memberships.
probabilityList of formatted conditional probability matrices per item.
Log.Lik.historyVector tracking log-likelihood at each EM iteration.
Log.Lik.nrepVector of log-likelihoods from each replication run.
modelTrained neural network model object (only when method="NNE").
callThe original function call used for model estimation.
argumentsList containing all input arguments passed to the LCA function.
LPALatent Profile Analysis model results. Available components:
paramsList containing all estimated model parameters.
means\(L \times I\) matrix of estimated mean vectors for each profile.
covs\(I \times I \times L\) array of estimated covariance matrices.
P.ZVector of length \(L\) with profile prior probabilities.
nparNumber of free parameters (depends on constraint).
Log.LikLog-likelihood of the final model.
AICAkaike Information Criterion.
BICBayesian Information Criterion.
best_BICBest BIC value across replication runs (if nrep > 1).
P.Z.Xn\(N \times L\) matrix of posterior profile probabilities.
ZVector of length \(N\) with MAP-classified profile memberships.
Log.Lik.historyVector tracking log-likelihood at each EM iteration.
Log.Lik.nrepVector of log-likelihoods from each replication run.
modelTrained model object (neural network or Mplus).
callThe original function call used for model estimation.
argumentsList containing all input arguments passed to the LPA function.
constraintCovariance structure constraints applied during estimation (from original arguments).
LCPALatent Class/Profile Analysis (with covariates). Available components:
betaInitial class coefficients (p1 x L matrix).
beta.seStandard errors for beta.
beta.Z.staZ-statistics for beta.
beta.p.value.tail1One-tailed p-values for beta.
beta.p.value.tail2Two-tailed p-values for beta.
P.Z.XnPosterior probabilities (N x L).
P.ZPrior proportions (length L).
ZModal class assignments (length N).
nparNumber of free parameters.
Log.LikLog-likelihood.
AICAIC.
BICBIC.
iterationsOptimization iterations in Step 3.
coveragedLogical: did optimization converge early?
paramsStep 1 model parameters (LCA/LPA output).
callFunction call.
argumentsInput arguments list.
LTALatent Transition Analysis model results. Available components:
betaInitial class coefficients (p1 x L matrix).
gammaTransition coefficients (nested list).
beta.seStandard errors for beta.
gamma.seStandard errors for gamma.
beta.Z.staZ-statistics for beta.
gamma.Z.staZ-statistics for gamma.
beta.p.value.tail1One-tailed p-values for beta.
gamma.p.value.tail1One-tailed p-values for gamma.
beta.p.value.tail2Two-tailed p-values for beta.
gamma.p.value.tail2Two-tailed p-values for gamma.
P.Z.XnsList of posterior probabilities per time (each N x L).
P.ZsList of prior proportions per time (each length L).
ZsList of modal class assignments per time (each length N).
nparNumber of free parameters.
Log.LikLog-likelihood.
AICAIC.
BICBIC.
iterationsOptimization iterations in Step 3.
coveragedLogical: did optimization converge early?
paramsStep 1 model parameters (LCA/LPA output).
callFunction call.
argumentsInput arguments list.
sim.LCASimulated Latent Class Analysis data. Available components:
responseInteger matrix (\(N \times I\)) of simulated categorical observations.
parArray (\(L \times I \times P_{\max}\)) of true class-specific category probabilities.
ZInteger vector (length \(N\)) of true latent class assignments.
P.ZNumeric vector (length \(L\)) of true class proportions.
poly.valueInteger vector (length \(I\)) specifying categories per variable.
P.Z.XnBinary matrix (\(N \times L\)) of true class membership indicators.
callThe original function call used for simulation.
argumentsList containing all input arguments passed to sim.LCA.
sim.LPASimulated Latent Profile Analysis data. Available components:
responseNumeric matrix (\(N \times I\)) of simulated continuous observations.
means\(L \times I\) matrix of true class-specific means.
covs\(I \times I \times L\) array of true class-specific covariance matrices.
P.Z.Xn\(N \times L\) matrix of true class membership indicators.
P.ZNumeric vector (length \(L\)) of true class proportions.
ZInteger vector (length \(N\)) of true profile assignments.
constraintOriginal constraint specification passed to sim.LPA.
callThe original function call used for simulation.
argumentsList containing all input arguments passed to sim.LPA.
sim.LTASimulated Latent Transition Analysis data. Available components:
responsesList of response matrices per time point.
ZsList of true latent class assignments per time.
P.ZsList of true class proportions per time.
parTrue conditional probabilities (for categorical items).
meansTrue profile means (for continuous variables).
covsTrue covariance matrices per class and time.
poly.valueCategories per variable (for categorical items).
rateTransition rate matrix or structure.
covariatesSimulated covariate matrix.
betaTrue initial class coefficients.
gammaTrue transition coefficients.
callOriginal simulation function call.
argumentsInput arguments used in simulation.
fit.indexModel fit indices object. Available components:
nparNumber of free parameters in the model.
Log.LikLog-likelihood of the model.
-2LLDeviance statistic (-2 times log-likelihood).
AICAkaike Information Criterion.
BICBayesian Information Criterion.
SICSample-Size Adjusted BIC (-0.5 * BIC).
CAICConsistent AIC.
AWEApproximate Weight of Evidence.
SABICSample-Size Adjusted BIC (alternative formulation).
callOriginal function call that generated the fit indices.
argumentsList containing input arguments (includes original model object).
compare.modelModel comparison results. Available components:
nparNamed numeric vector with free parameters for each model (model1, model2).
entropyNamed numeric vector with entropy values for each model.
AvePPList of average posterior probabilities per class/profile for each model.
fit.indexList of get.fit.index objects for both models.
BFBayes Factor comparing models (based on SIC differences).
LRT.objStandard likelihood ratio test results (requires nested models).
LRT.VLMR.objVuong-Lo-Mendell-Rubin adjusted likelihood ratio test results.
LRT.Bootstrap.objParametric bootstrap likelihood ratio test results (if n.Bootstrap > 0).
callThe matched function call used for comparison.
argumentsList containing original input arguments (object1, object2, n.Bootstrap).
SEStandard error estimation results. Available components:
seList containing standard errors for parameters (components depend on model type).
vcovVariance-covariance matrix (only for method="Obs").
hessianObserved information matrix (only for method="Obs").
diagnosticsMethod-specific diagnostic information (e.g., estimation method).
callFunction call that generated the object.
argumentsInput arguments used in estimation.
meansStandard errors for profile means (LPA models only — accessed via se list).
covsStandard errors for covariance parameters (LPA models only — accessed via se list).
P.ZStandard errors for class proportions (both LCA/LPA — accessed via se list).
parStandard errors for conditional probabilities (LCA models only — accessed via se list).
set.seed(123)
# Simulate LPA data: 500 observations, 3 continuous variables, 2 latent profiles
# Constraint "E0": Equal variances across classes, zero covariances
data.obj <- sim.LPA(N = 500, I = 3, L = 2, constraint = "E0")
# Extract the simulated response matrix (N x I) for model fitting
response <- extract(data.obj, "response")
# Extract the TRUE covariance matrices (I x I x L array)
extract(data.obj, "covs")
# Fit an LPA model to the simulated data using the SAME constraint ("E0")
fit_E0 <- LPA(response, L = 2, constraint = "E0")
# Extract the ESTIMATED covariance matrices from the fitted model
extract(fit_E0, "covs")
# Simulate LCA data: 30 observations, 5 categorical items, 3 latent classes
sim_data <- sim.LCA(N = 30, I = 5, L = 3)
# Extract the TRUE conditional probability array
extract(sim_data, "par")
Run the code above in your browser using DataLab