Learn R Programming

LCPA (version 1.0.0)

extract: S3 Methods: extract

Description

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.

Usage

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, ...)

Value

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.

Arguments

object

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.

what

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).

Methods (by class)

  • 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

Usage Notes

  • 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 (...).

Details

This function supports extraction from ten primary object classes. Below are available components for each:

LCA

Latent Class Analysis model results. Available components:

params

List containing all estimated model parameters.

par

3D array (\(L \times I \times K_{\max}\)) of conditional response probabilities.

P.Z

Vector of length \(L\) with latent class prior probabilities.

npar

Number of free parameters in the model.

Log.Lik

Log-likelihood of the final model.

AIC

Akaike Information Criterion.

BIC

Bayesian Information Criterion.

best_BIC

Best BIC value across replication runs (if nrep > 1).

P.Z.Xn

\(N \times L\) matrix of posterior class probabilities.

Z

Vector of length \(N\) with MAP-classified latent class memberships.

probability

List of formatted conditional probability matrices per item.

Log.Lik.history

Vector tracking log-likelihood at each EM iteration.

Log.Lik.nrep

Vector of log-likelihoods from each replication run.

model

Trained neural network model object (only when method="NNE").

call

The original function call used for model estimation.

arguments

List containing all input arguments passed to the LCA function.

LPA

Latent Profile Analysis model results. Available components:

params

List 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.Z

Vector of length \(L\) with profile prior probabilities.

npar

Number of free parameters (depends on constraint).

Log.Lik

Log-likelihood of the final model.

AIC

Akaike Information Criterion.

BIC

Bayesian Information Criterion.

best_BIC

Best BIC value across replication runs (if nrep > 1).

P.Z.Xn

\(N \times L\) matrix of posterior profile probabilities.

Z

Vector of length \(N\) with MAP-classified profile memberships.

Log.Lik.history

Vector tracking log-likelihood at each EM iteration.

Log.Lik.nrep

Vector of log-likelihoods from each replication run.

model

Trained model object (neural network or Mplus).

call

The original function call used for model estimation.

arguments

List containing all input arguments passed to the LPA function.

constraint

Covariance structure constraints applied during estimation (from original arguments).

LCPA

Latent Class/Profile Analysis (with covariates). Available components:

beta

Initial class coefficients (p1 x L matrix).

beta.se

Standard errors for beta.

beta.Z.sta

Z-statistics for beta.

beta.p.value.tail1

One-tailed p-values for beta.

beta.p.value.tail2

Two-tailed p-values for beta.

P.Z.Xn

Posterior probabilities (N x L).

P.Z

Prior proportions (length L).

Z

Modal class assignments (length N).

npar

Number of free parameters.

Log.Lik

Log-likelihood.

AIC

AIC.

BIC

BIC.

iterations

Optimization iterations in Step 3.

coveraged

Logical: did optimization converge early?

params

Step 1 model parameters (LCA/LPA output).

call

Function call.

arguments

Input arguments list.

LTA

Latent Transition Analysis model results. Available components:

beta

Initial class coefficients (p1 x L matrix).

gamma

Transition coefficients (nested list).

beta.se

Standard errors for beta.

gamma.se

Standard errors for gamma.

beta.Z.sta

Z-statistics for beta.

gamma.Z.sta

Z-statistics for gamma.

beta.p.value.tail1

One-tailed p-values for beta.

gamma.p.value.tail1

One-tailed p-values for gamma.

beta.p.value.tail2

Two-tailed p-values for beta.

gamma.p.value.tail2

Two-tailed p-values for gamma.

P.Z.Xns

List of posterior probabilities per time (each N x L).

P.Zs

List of prior proportions per time (each length L).

Zs

List of modal class assignments per time (each length N).

npar

Number of free parameters.

Log.Lik

Log-likelihood.

AIC

AIC.

BIC

BIC.

iterations

Optimization iterations in Step 3.

coveraged

Logical: did optimization converge early?

params

Step 1 model parameters (LCA/LPA output).

call

Function call.

arguments

Input arguments list.

sim.LCA

Simulated Latent Class Analysis data. Available components:

response

Integer matrix (\(N \times I\)) of simulated categorical observations.

par

Array (\(L \times I \times P_{\max}\)) of true class-specific category probabilities.

Z

Integer vector (length \(N\)) of true latent class assignments.

P.Z

Numeric vector (length \(L\)) of true class proportions.

poly.value

Integer vector (length \(I\)) specifying categories per variable.

P.Z.Xn

Binary matrix (\(N \times L\)) of true class membership indicators.

call

The original function call used for simulation.

arguments

List containing all input arguments passed to sim.LCA.

sim.LPA

Simulated Latent Profile Analysis data. Available components:

response

Numeric 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.Z

Numeric vector (length \(L\)) of true class proportions.

Z

Integer vector (length \(N\)) of true profile assignments.

constraint

Original constraint specification passed to sim.LPA.

call

The original function call used for simulation.

arguments

List containing all input arguments passed to sim.LPA.

sim.LTA

Simulated Latent Transition Analysis data. Available components:

responses

List of response matrices per time point.

Zs

List of true latent class assignments per time.

P.Zs

List of true class proportions per time.

par

True conditional probabilities (for categorical items).

means

True profile means (for continuous variables).

covs

True covariance matrices per class and time.

poly.value

Categories per variable (for categorical items).

rate

Transition rate matrix or structure.

covariates

Simulated covariate matrix.

beta

True initial class coefficients.

gamma

True transition coefficients.

call

Original simulation function call.

arguments

Input arguments used in simulation.

fit.index

Model fit indices object. Available components:

npar

Number of free parameters in the model.

Log.Lik

Log-likelihood of the model.

-2LL

Deviance statistic (-2 times log-likelihood).

AIC

Akaike Information Criterion.

BIC

Bayesian Information Criterion.

SIC

Sample-Size Adjusted BIC (-0.5 * BIC).

CAIC

Consistent AIC.

AWE

Approximate Weight of Evidence.

SABIC

Sample-Size Adjusted BIC (alternative formulation).

call

Original function call that generated the fit indices.

arguments

List containing input arguments (includes original model object).

compare.model

Model comparison results. Available components:

npar

Named numeric vector with free parameters for each model (model1, model2).

entropy

Named numeric vector with entropy values for each model.

AvePP

List of average posterior probabilities per class/profile for each model.

fit.index

List of get.fit.index objects for both models.

BF

Bayes Factor comparing models (based on SIC differences).

LRT.obj

Standard likelihood ratio test results (requires nested models).

LRT.VLMR.obj

Vuong-Lo-Mendell-Rubin adjusted likelihood ratio test results.

LRT.Bootstrap.obj

Parametric bootstrap likelihood ratio test results (if n.Bootstrap > 0).

call

The matched function call used for comparison.

arguments

List containing original input arguments (object1, object2, n.Bootstrap).

SE

Standard error estimation results. Available components:

se

List containing standard errors for parameters (components depend on model type).

vcov

Variance-covariance matrix (only for method="Obs").

hessian

Observed information matrix (only for method="Obs").

diagnostics

Method-specific diagnostic information (e.g., estimation method).

call

Function call that generated the object.

arguments

Input arguments used in estimation.

means

Standard errors for profile means (LPA models only — accessed via se list).

covs

Standard errors for covariance parameters (LPA models only — accessed via se list).

P.Z

Standard errors for class proportions (both LCA/LPA — accessed via se list).

par

Standard errors for conditional probabilities (LCA models only — accessed via se list).

Examples

Run this code
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