Title: | Structural Modeling for Multiple Latent Class Variables |
---|---|
Description: | Provides comprehensive tools for the implementation of Structural Latent Class Models (SLCM), including Latent Transition Analysis (LTA; Linda M. Collins and Stephanie T. Lanza, 2009) <doi:10.1002/9780470567333>, Latent Class Profile Analysis (LCPA; Hwan Chung et al., 2010) <doi:10.1111/j.1467-985x.2010.00674.x>, and Joint Latent Class Analysis (JLCA; Saebom Jeon et al., 2017) <doi:10.1080/10705511.2017.1340844>, and any other extended models involving multiple latent class variables. |
Authors: | Youngsun Kim [aut, cre] , Hwan Chung [aut] |
Maintainer: | Youngsun Kim <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.2.0 |
Built: | 2024-11-19 04:41:22 UTC |
Source: | https://github.com/kim0sun/slca |
This dataset includes responses from the National Longitudinal Study of Adolescent Health (Add Health),
focusing on adolescents' experiences with depression. The subjects, who were in Grades 10 and 11 during
the 1994-1995 academic year, provided data on at least one measure of adolescent delinquency in Wave 1.
These data can be used to replicate the latent class analysis conducted by Collins and Lanza (2008).
The dataset includes five covariates, notably grade level and sex of respondents, along with variables
capturing depressive emotions: sadness (S1-S4
), feeling disliked (D1-D2
), and feelings of failure (F1-F2
).
A data frame with 2061 rows and 18 variables:
GRADE
Respondent's grade level at Wave I
SEX
Respondent's sex
levels: (1)Male
, (2)Female
S1w1
, S1w2
I felt that I could not shake off the blues even with help from my family and friends.
S2w1
, S2w2
I felt depressed.
S3w1
, S3w2
I felt lonely.
S4w1
, S4w2
I felt sad.
D1w1
, D1w2
People were unfriendly to me.
D2w1
, D2w2
I felt that people disliked me
F1w1
, F1w2
I thought my life had been a failure.
F2w1
, F2w2
I felt life was not worth living
Responses for these variables were initially categorized as "Never," "Sometimes," "Often," or "Most or All of the Time."
In this dataset, responses are recoded as "No" for "Never" and "Yes" for all other responses, providing
a longitudinal perspective on adolescent depression from Waves I and II. Variables with suffix "w1"
are from Wave I,
and those with suffix "w2"
are from Wave II.
https://addhealth.cpc.unc.edu/data/#public-use
Collins, L.M., & Lanza, S.T. (2009). Latent Class and Latent Transition Analysis: With Applications in the Social, Behavioral, and Health Sciences.
J.R. Udry. The National Longitudinal Study of Adolescent Health (Add Health), Waves I & II, 1994-1996. Carolina Population Center, University of North Carolina at Chapel Hill, Chapel Hill, NC, 2003.
library(magrittr) lta5 <- slca( DEP1(5) ~ S1w1 + S2w1 + S3w1 + S4w1 + D1w1 + D2w1 + F1w1 + F2w1, DEP2(5) ~ S1w2 + S2w2 + S3w2 + S4w2 + D1w2 + D2w2 + F1w2 + F2w2, DEP1 ~ DEP2 ) %>% estimate(addhealth) lta5inv <- slca( DEP1(5) ~ S1w1 + S2w1 + S3w1 + S4w1 + D1w1 + D2w1 + F1w1 + F2w1, DEP2(5) ~ S1w2 + S2w2 + S3w2 + S4w2 + D1w2 + D2w2 + F1w2 + F2w2, DEP1 ~ DEP2, constraints = c("DEP1", "DEP2") ) %>% estimate(addhealth) compare(lta5inv, lta5, test = "chisq") lta5inv %>% param()
library(magrittr) lta5 <- slca( DEP1(5) ~ S1w1 + S2w1 + S3w1 + S4w1 + D1w1 + D2w1 + F1w1 + F2w1, DEP2(5) ~ S1w2 + S2w2 + S3w2 + S4w2 + D1w2 + D2w2 + F1w2 + F2w2, DEP1 ~ DEP2 ) %>% estimate(addhealth) lta5inv <- slca( DEP1(5) ~ S1w1 + S2w1 + S3w1 + S4w1 + D1w1 + D2w1 + F1w1 + F2w1, DEP2(5) ~ S1w2 + S2w2 + S3w2 + S4w2 + D1w2 + D2w2 + F1w2 + F2w2, DEP1 ~ DEP2, constraints = c("DEP1", "DEP2") ) %>% estimate(addhealth) compare(lta5inv, lta5, test = "chisq") lta5inv %>% param()
slca
ModelsProvides relative model fit test for two fitted SLCM models with deviance statistic.
compare( model1, model2, test = c("none", "chisq", "boot"), nboot = 50, method = c("hybrid", "em", "nlm"), plot = FALSE, maxiter = 1000, tol = 1e-08, verbose = FALSE )
compare( model1, model2, test = c("none", "chisq", "boot"), nboot = 50, method = c("hybrid", "em", "nlm"), plot = FALSE, maxiter = 1000, tol = 1e-08, verbose = FALSE )
model1 |
an object of class |
model2 |
another object of class |
test |
a character string specifying the type of test to be conducted. If |
nboot |
an integer specifying the number of bootstrap rounds to be performed. |
method |
estimation method for bootstrapping. |
plot |
a logical value indicating whether to print histogram of G-squared statistics for boostrap samples, only for |
maxiter |
an integer specifying maximum number of iterations allowed for the estimation process of each bootstrapping round. |
tol |
a numeric value setting tolerance for the convergence of each bootstrapping round. |
verbose |
a logical value indicating whether to print progress updates on the number of bootstrapping rounds completed. |
A data.frame
containing the number of parameters (Df), loglikelihood, AIC, BIC, G-squared statistics, and the residual degree of freedom for each object.
Depending on the test
argument, the p-value for the corresponding statistical test may also be included.
library(magrittr) data <- gss7677[gss7677$COHORT == "YOUNG", ] stat2 <- slca(status(2) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat3 <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat4 <- slca(status(4) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) gof(stat2, stat3, stat4) gof(stat2, stat3, stat4, test = "chisq") gof(stat2, stat3, stat4, test = "boot") compare(stat3, stat4) compare(stat3, stat4, test = "chisq") compare(stat3, stat4, test = "boot")
library(magrittr) data <- gss7677[gss7677$COHORT == "YOUNG", ] stat2 <- slca(status(2) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat3 <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat4 <- slca(status(4) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) gof(stat2, stat3, stat4) gof(stat2, stat3, stat4, test = "chisq") gof(stat2, stat3, stat4, test = "boot") compare(stat3, stat4) compare(stat3, stat4, test = "chisq") compare(stat3, stat4, test = "boot")
Computes confidence intervals for one or more parameters of fitted model. Package slca adds methods for slca
fits.
## S3 method for class 'slca' confint(object, parm, level = 0.95, type = c("param", "logit"), ...)
## S3 method for class 'slca' confint(object, parm, level = 0.95, type = c("param", "logit"), ...)
object |
an object of class |
parm |
an integer string specifying parameters to be given confidence intervals. |
level |
numeric value representing the desired confidence level for the intervals, with a default of 0.95. |
type |
a character string specifying the format in which the results should be returned. Options include |
... |
additional arguments. |
A matrix
with two columns representing the confidence intervals for the selected parameters. The columns are named based on the specified confidence level (level
):
100 * (level / 2) %
: This column shows the lower bound of the confidence interval.
100 * (1 - level / 2) %
: This column shows the upper bound of the confidence interval.
The level
parameter specifies the confidence level, with common values being 0.05 for a 95% confidence interval and 0.01 for a 99% confidence interval.
param(nlsy_jlcpa, index = TRUE) confint(nlsy_jlcpa) confint(nlsy_jlcpa, 1:4)
param(nlsy_jlcpa, index = TRUE) confint(nlsy_jlcpa) confint(nlsy_jlcpa, 1:4)
slca
ObjectEstimate the parameters of model constructed using the slca
function.
estimate(x, ...) ## S3 method for class 'slca' estimate(x, data, method = c("em", "hybrid", "nlm"), fix2zero = NULL, control = slcaControl(), ...)
estimate(x, ...) ## S3 method for class 'slca' estimate(x, data, method = c("em", "hybrid", "nlm"), fix2zero = NULL, control = slcaControl(), ...)
x |
an |
... |
additional arguments. |
data |
a |
method |
estimation method for SLCM parameters. The default is |
fix2zero |
a |
control |
a |
To constrain certain parameters to zero, use the fix2zero
argument. Each parameter is associated with a unique index. You can identify the index of a specific parameter by invoking the param function with the index = TRUE
argument. To apply these constraints, include the relevant parameter indices in the fix2zero
argument.
An object of class slca
and estimated
with an following elements:
model |
a |
method |
the method used for estimation |
arg |
the brief model description used during the estimation. |
mf |
the data.frame used for estimation. |
par |
the log of the estimated paramters. |
logit |
the log-odds of the estimated parameters. |
score |
the score function for the estimated parameters. |
posterior |
the |
convergence |
a logical indicator of whether convergence was achieved. |
loglikelihood |
the loglikelihood of the estimated model. |
control |
the control values used during the estimation process. |
This returned object can be further processed using the param functions to extract the estimated parameters or their respective standard errors. Additionally, the regress function enables logistic regression analysis using three-step approach to evaluate the effect of external variables on latent class variables.
slca param regress slcaControl gss7677, addhealth, nlsy97
slca
ModelProvides AIC, BIC and deviance statistic (G-squared) for goodness of fit test for the fitted model. Absolute model fit can be tested with deviance statistics, if test
argument is specified.
gof(object, ...) ## S3 method for class 'slca' gof( object, ..., test = c("none", "chisq", "boot"), nboot = 100, plot = FALSE, maxiter = 100, tol = 1e-6, verbose = FALSE )
gof(object, ...) ## S3 method for class 'slca' gof( object, ..., test = c("none", "chisq", "boot"), nboot = 100, plot = FALSE, maxiter = 100, tol = 1e-6, verbose = FALSE )
object |
an object of class |
... |
additional objects of class |
test |
a character string specifying the type of test to be conducted. If |
nboot |
an integer specifying the number of bootstrap rounds to be performed. |
plot |
a logical value indicating whether to print histogram of G-squared statistics for boostrap samples, only for |
maxiter |
an integer specifying maximum number of iterations allowed for the estimation process of each bootstrapping round. |
tol |
a numeric value setting tolerance for the convergence of each bootstrapping round. |
verbose |
a logical value indicating whether to print progress updates on the number of bootstrapping rounds completed. |
A data.frame
containing the number of parameters (Df), loglikelihood, AIC, BIC, G-squared statistics, and the residual degree of freedom for each object.
Depending on the test
argument, the p-value for the corresponding statistical test may also be included.
library(magrittr) data <- gss7677[gss7677$COHORT == "YOUNG", ] stat2 <- slca(status(2) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat3 <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat4 <- slca(status(4) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) gof(stat2, stat3, stat4) gof(stat2, stat3, stat4, test = "chisq") gof(stat2, stat3, stat4, test = "boot") compare(stat3, stat4) compare(stat3, stat4, test = "chisq") compare(stat3, stat4, test = "boot")
library(magrittr) data <- gss7677[gss7677$COHORT == "YOUNG", ] stat2 <- slca(status(2) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat3 <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) stat4 <- slca(status(4) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) gof(stat2, stat3, stat4) gof(stat2, stat3, stat4, test = "chisq") gof(stat2, stat3, stat4, test = "boot") compare(stat3, stat4) compare(stat3, stat4, test = "chisq") compare(stat3, stat4, test = "boot")
This dataset contains responses from the General Social Survey (GSS) for the years 1976 and 1977, focusing on social status and tolerance towards minorities
The latent class models can be fitted using this dataset replicate the analysis carried on McCutcheon (1985) and Bakk et al. (2014).
The data contains some covariates including year of the interview, age, sex, race, degree, and income of respondents.
The variables associating social status include father's occupation and education level, and mother's education level, while the variables associating tolerance towards minorities are created by agreeing three related questions: (1) allowing public speaking, (2) allowing teaching, and (3) allowing literatures.
A data frame with 2942 rows and 14 variables:
YEAR
Interview year (1976, 1977)
COHORT
Respondent's age
levels: (1)YOUNG
, (2)YOUNG-MIDDLE
, (4)MIDDLE
, (5)OLD
SEX
Respondent's sex
levels: (1)MALE
, (2)FEMALE
RACE
Respondent's race
levels: (1)WHITE
(2)BLACK
, (3)OTHER
DEGREE
Respondent's degree
levels: (1)LT HS
, (2)HIGH-SCH
, (3)HIGHER
REALRINC
Income of respondents
PAPRES
Father's prestige (occupation)
levels: (1)LOW
, (2)MIDIUM
, (2)HIGH
PADEG
Father's degree
levels: (1)LT HS
, (2)HIGH-SCH
, (3)COLLEGE
, (4) BACHELOR
, (5)GRADUATE
MADEG
Mother's degree
levels: (1)LT HS
, (2)HIGH-SCH
, (3)COLLEGE
, (4) BACHELOR
, (5)GRADUATE
TOLRAC
Tolerance towards racists
TOLCOM
Tolerance towards communists
TOLHOMO
Tolerance towards homosexuals
TOLATH
Tolerance towards atheists
TOLMIL
Tolerance towards militarists
General Social Survey (GSS) 1976, 1977
Bakk Z, Kuha J. (2021) Relating latent class membership to external variables: An overview. Br J Math Stat Psychol. 74(2):340-362.
McCutcheon, A. L. (1985). A latent class analysis of tolerance for nonconformity in the American public. Public Opinion Quarterly, 49, 474–488.
library(magrittr) data <- gss7677[gss7677$RACE == "BLACK",] model_stat <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_stat) param(model_stat) model_tol <- slca(tol(4) ~ TOLRAC + TOLCOM + TOLHOMO + TOLATH + TOLMIL) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_tol) param(model_tol) model_lta <- slca( status(3) ~ PAPRES + PADEG + MADEG, tol(4) ~ TOLRAC + TOLCOM + TOLHOMO + TOLATH + TOLMIL, status ~ tol ) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_lta) param(model_lta) regress(model_lta, status ~ SEX, data) regress(model_lta, status ~ SEX, data, method = "BCH") regress(model_lta, status ~ SEX, data, method = "ML")
library(magrittr) data <- gss7677[gss7677$RACE == "BLACK",] model_stat <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_stat) param(model_stat) model_tol <- slca(tol(4) ~ TOLRAC + TOLCOM + TOLHOMO + TOLATH + TOLMIL) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_tol) param(model_tol) model_lta <- slca( status(3) ~ PAPRES + PADEG + MADEG, tol(4) ~ TOLRAC + TOLCOM + TOLHOMO + TOLATH + TOLMIL, status ~ tol ) %>% estimate(data = data, control = list(verbose = FALSE)) summary(model_lta) param(model_lta) regress(model_lta, status ~ SEX, data) regress(model_lta, status ~ SEX, data, method = "BCH") regress(model_lta, status ~ SEX, data, method = "ML")
The slca
model estimated using NLSY97 data
An slca
object estimated
for JLCPA model using nlsy97
.
Bureau of Labor Statistics, U.S. Department of Labor. National Longitudinal Survey of Youth 1997 cohort, 1997-2017 (rounds 1-18). Produced and distributed by the Center for Human Resource Research (CHRR), The Ohio State University. Columbus, OH: 2019.
Jeon, S., Seo, T. S., Anthony, J. C., & Chung, H. (2022). Latent Class Analysis for Repeatedly Measured Multiple Latent Class Variables. Multivariate Behavioral Research, 57(2–3), 341–355.
A dataset containing substance use behavior from the National Longitudinal Survey of Youth 1997 (NLSY97) for three years: 1998, 2003, and 2008. The dataset focuses on the youth born in 1984 and tracks three substance use behaviors: tobacco/cigarette smoking, alcohol drinking, and marijuana use.
A data frame with 1004 rows and 38 columns:
Respondent's sex
Respondent's race
(Ever smoked) Ever smoked in 1998, 2003, and 2008 (0: No, 1: Yes)
(Frequent smoke) Monthly smokes in 1998, 2003, and 2008 (0: No, 1: Yes)
(Daily smoke) Daily smokes in 1998, 2003, and 2008 (0: No, 1: Yes)
(Heavy smoke) 10+ cigarettes per day in 1998, 2003, and 2008 (0: No, 1: Yes)
(Ever drunk) Have you ever drunk in 1998, 2003, and 2008? (0: No, 1: Yes)
(Current drinker) Monthly drinking in 1998, 2003, and 2008 (0: No, 1: Yes)
(Weakly drinker) 5+ days drinking in a month in 1998, 2003, and 2008 (0: No, 1: Yes)
(Binge drinker) 5+ drinks on the same day at least one time in the last 30 day (0: No, 1: Yes)
(Ever marijuana used) Have you ever used marijuana in 1998, 2003, and 2008? (0: No, 1: Yes)
(Corrent marijuana user) Monthly marijuana use in 1998, 2003, and 2008 (0: No, 1: Yes)
(Occasional marijuana user) 10+ days marijuana use in a month in 1998, 2003, and 2008 (0: No, 1: Yes)
(School/work marijuana user) Marijuana use before/during school or work in 1998, 2003, and 2008 (0: No, 1: Yes)
Similar naming conventions apply for the years 2003 and 2008, replacing '98' with '03' and '08', respectively.
National Longitudinal Survey of Youth 1997 (NLSY97)
Bureau of Labor Statistics, U.S. Department of Labor. National Longitudinal Survey of Youth 1997 cohort, 1997-2017 (rounds 1-18). Produced and distributed by the Center for Human Resource Research (CHRR), The Ohio State University. Columbus, OH: 2019.
library(magrittr) nlsy_smoke <- slca(smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98) %>% estimate(data = nlsy97, control = list(verbose = FALSE)) summary(nlsy_smoke) # JLCA model_jlca <- slca( smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98, drk98(3) ~ EDRK_98 + CDRK_98 + WDRK_98 + BDRK_98, mrj98(3) ~ EMRJ_98 + CMRJ_98 + OMRJ_98 + SMRJ_98, substance(4) ~ smk98 + drk98 + mrj98 ) %>% estimate(data = nlsy97, control = list(verbose = FALSE)) summary(model_jlca) param(model_jlca) # JLCPA nlsy_jlcpa <- slca( smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98, drk98(3) ~ EDRK_98 + CDRK_98 + WDRK_98 + BDRK_98, mrj98(3) ~ EMRJ_98 + CMRJ_98 + OMRJ_98 + SMRJ_98, use98(5) ~ smk98 + drk98 + mrj98, smk03(3) ~ ESMK_03 + FSMK_03 + DSMK_03 + HSMK_03, drk03(3) ~ EDRK_03 + CDRK_03 + WDRK_03 + BDRK_03, mrj03(3) ~ EMRJ_03 + CMRJ_03 + OMRJ_03 + SMRJ_03, use03(5) ~ smk03 + drk03 + mrj03, smk08(3) ~ ESMK_08 + FSMK_08 + DSMK_08 + HSMK_08, drk08(3) ~ EDRK_08 + CDRK_08 + WDRK_08 + BDRK_08, mrj08(3) ~ EMRJ_08 + CMRJ_08 + OMRJ_08 + SMRJ_08, use08(5) ~ smk08 + drk08 + mrj08, prof(4) ~ use98 + use03 + use08, constraints = list( c("smk98", "smk03", "smk08"), c("drk98", "drk03", "drk08"), c("mrj98", "mrj03", "mrj08"), c("use98 ~ smk98", "use03 ~ smk03", "use08 ~ smk08"), c("use98 ~ drk98", "use03 ~ drk03", "use08 ~ drk08"), c("use98 ~ mrj98", "use03 ~ mrj03", "use08 ~ mrj08") ) ) %>% estimate(nlsy97, control = list(verbose = FALSE))
library(magrittr) nlsy_smoke <- slca(smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98) %>% estimate(data = nlsy97, control = list(verbose = FALSE)) summary(nlsy_smoke) # JLCA model_jlca <- slca( smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98, drk98(3) ~ EDRK_98 + CDRK_98 + WDRK_98 + BDRK_98, mrj98(3) ~ EMRJ_98 + CMRJ_98 + OMRJ_98 + SMRJ_98, substance(4) ~ smk98 + drk98 + mrj98 ) %>% estimate(data = nlsy97, control = list(verbose = FALSE)) summary(model_jlca) param(model_jlca) # JLCPA nlsy_jlcpa <- slca( smk98(3) ~ ESMK_98 + FSMK_98 + DSMK_98 + HSMK_98, drk98(3) ~ EDRK_98 + CDRK_98 + WDRK_98 + BDRK_98, mrj98(3) ~ EMRJ_98 + CMRJ_98 + OMRJ_98 + SMRJ_98, use98(5) ~ smk98 + drk98 + mrj98, smk03(3) ~ ESMK_03 + FSMK_03 + DSMK_03 + HSMK_03, drk03(3) ~ EDRK_03 + CDRK_03 + WDRK_03 + BDRK_03, mrj03(3) ~ EMRJ_03 + CMRJ_03 + OMRJ_03 + SMRJ_03, use03(5) ~ smk03 + drk03 + mrj03, smk08(3) ~ ESMK_08 + FSMK_08 + DSMK_08 + HSMK_08, drk08(3) ~ EDRK_08 + CDRK_08 + WDRK_08 + BDRK_08, mrj08(3) ~ EMRJ_08 + CMRJ_08 + OMRJ_08 + SMRJ_08, use08(5) ~ smk08 + drk08 + mrj08, prof(4) ~ use98 + use03 + use08, constraints = list( c("smk98", "smk03", "smk08"), c("drk98", "drk03", "drk08"), c("mrj98", "mrj03", "mrj08"), c("use98 ~ smk98", "use03 ~ smk03", "use08 ~ smk08"), c("use98 ~ drk98", "use03 ~ drk03", "use08 ~ drk08"), c("use98 ~ mrj98", "use03 ~ mrj03", "use08 ~ mrj08") ) ) %>% estimate(nlsy97, control = list(verbose = FALSE))
slca
ObjectThis function prints the estimated parameters of the slca
model by accepting an estimated
slca
object.
param(object, ...) ## S3 method for class 'slca' param( object, type = c("probs", "logit"), se = FALSE, index = FALSE, ... )
param(object, ...) ## S3 method for class 'slca' param( object, type = c("probs", "logit"), se = FALSE, index = FALSE, ... )
object |
an object of class |
... |
additional arguments. |
type |
a character string specifying the format in which the estimated parameters should be displayed. The options are |
se |
a logical indicating whether standard errors (TRUE) or parameter estimates (FALSE) should be displayed. |
index |
a logical indicating whether to include ( |
A list
containing the specified estimated parameters or their standard errors if se
is set to TRUE
. The components of the list include:
pi |
Membership probabilities of the root variable. |
tau |
Conditional probabilities between latent class variables, represented with uppercase alphabets for considering measurement invariance. |
rho |
Item response probabilities for each measurement model, represented with lowercase alphabets for considering measurement invariance. |
This function performs regression analysis to explore the influence of exogenous (external) variables on the latent class variables within an estimated slca
model. It utilizes logistic regression and employs a three-step approach.
regress(object, ...) ## S3 method for class 'slca' regress( object, formula, data = parent.frame(), imputation = c("modal", "prob"), method = c("naive", "BCH", "ML"), ... )
regress(object, ...) ## S3 method for class 'slca' regress( object, formula, data = parent.frame(), imputation = c("modal", "prob"), method = c("naive", "BCH", "ML"), ... )
object |
an object of class |
... |
additional arguments. |
formula |
a formula defining the regression model, including both latent class variables from the estimated model and any exogenous (external) variables. |
data |
an optional data frame containing the exogenous variables of interest. |
imputation |
the imputation method for imputing (assigning) latent class variables. Possible values are:
|
method |
the method used to adjust bias in the three-step approach, with options including "naive", "BCH", and "ML". |
A list
with following components:
coefficients |
a matrix of regression coefficients representing the odds ratios of each class against the baseline class (the last class). |
std.err |
a matrix of standard errors corresponding to the regression coefficients. |
vcov |
the calculated variance-covariance matrix for the regression coefficients. |
dim |
the dimensions of the coefficients matrix. |
ll |
the log likelihood of the regression model. |
Using the summary
function, you can print coefficients, standard errors, corresponding Wald statistics, and p-values for these statistics.
Vermunt, J. K. (2010). Latent Class Modeling with Covariates: Two Improved Three-Step Approaches. Political Analysis, 18(4), 450–469. http://www.jstor.org/stable/25792024
library(magrittr) names(nlsy97) nlsy_jlcpa %>% regress(smk98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(drk98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(mrj98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(use98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(prof ~ SEX, nlsy97)
library(magrittr) names(nlsy97) nlsy_jlcpa %>% regress(smk98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(drk98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(mrj98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(use98 ~ SEX, nlsy97) nlsy_jlcpa %>% regress(prof ~ SEX, nlsy97)
This function reorders the latent class membership for specified latent class variables.
## S3 method for class 'slca' reorder(x, ...)
## S3 method for class 'slca' reorder(x, ...)
x |
an object of class |
... |
additional arguments specifying the new order for the latent class variables. |
Returns the modified slca
or estimated
object with the reordered latent classes.
library(magrittr) nlsy_jlcpa %>% param # Reorder the RHO parameters as ascending order reordered1 <- nlsy_jlcpa %>% reorder(smk98 = c(2, 3, 1), drk98 = c(2, 1, 3), mrj98 = c(3, 2, 1)) reordered1 %>% param # Label class1: nonuse # class2: lifetime use # class3: current use # Reorder the TAU parameters for joint classes as ascending order reordered2 <- reordered1 %>% reorder(use98 = c(5, 1, 4, 2, 3)) reordered2 %>% param # Label class1: nonuse # class2: heavy drinking only # class3: not heavy use # class4: heavy drinking & smoking # class5: heavy use # Reorder the TAU paramters for profiles as ascending order reordered3 <- reordered2 %>% reorder(prof = c(4, 1, 3, 2)) reordered3 %>% param # Label class1: nonuse stayer # class2: heavy drinking advancer # class3: heavy drk & smk advancer # class4: heavy use advancer
library(magrittr) nlsy_jlcpa %>% param # Reorder the RHO parameters as ascending order reordered1 <- nlsy_jlcpa %>% reorder(smk98 = c(2, 3, 1), drk98 = c(2, 1, 3), mrj98 = c(3, 2, 1)) reordered1 %>% param # Label class1: nonuse # class2: lifetime use # class3: current use # Reorder the TAU parameters for joint classes as ascending order reordered2 <- reordered1 %>% reorder(use98 = c(5, 1, 4, 2, 3)) reordered2 %>% param # Label class1: nonuse # class2: heavy drinking only # class3: not heavy use # class4: heavy drinking & smoking # class5: heavy use # Reorder the TAU paramters for profiles as ascending order reordered3 <- reordered2 %>% reorder(prof = c(4, 1, 3, 2)) reordered3 %>% param # Label class1: nonuse stayer # class2: heavy drinking advancer # class3: heavy drk & smk advancer # class4: heavy use advancer
slca
model.This function simulates data from a constructed slca
model. If the model is not already estimated, parameters can be specified by the user or generated randomly.
## S3 method for class 'slca' simulate(object, nsim = 500, seed = NULL, parm, nlevel, ...)
## S3 method for class 'slca' simulate(object, nsim = 500, seed = NULL, parm, nlevel, ...)
object |
a |
nsim |
the number of response observations to simulate. Defaults to 500. |
seed |
a random seed for reproducibility of the |
parm |
a set of parameters provided by the user to guide the simulation, if the model has not been estimated. |
nlevel |
the number of levels for each manifest item declared in the model. If not provided, the default is 2. |
... |
additional arguments. |
A list
of two components:
class |
A |
response |
A |
library(magrittr) model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5) sim_data <- model %>% simulate(nlevel = c(3, 3, 3, 3, 3)) y <- sim_data$response sapply(y, table) sim_data <- model %>% simulate(nlevel = c(x1 = 2, x3 = 3, x4 = 4, x5 = 5)) y <- sim_data$response sapply(y, table) model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5, lc2[4] ~ y1 + y2 + y3 + y4 + y5) sim_data <- model %>% simulate(1000) sapply(sim_data$class, table)
library(magrittr) model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5) sim_data <- model %>% simulate(nlevel = c(3, 3, 3, 3, 3)) y <- sim_data$response sapply(y, table) sim_data <- model %>% simulate(nlevel = c(x1 = 2, x3 = 3, x4 = 4, x5 = 5)) y <- sim_data$response sapply(y, table) model <- slca(lc1[3] ~ x1 + x2 + x3 + x4 + x5, lc2[4] ~ y1 + y2 + y3 + y4 + y5) sim_data <- model %>% simulate(1000) sapply(sim_data$class, table)
This function constructs a structural latent class model (SLCM) for specified latent class variables.
slca(formula = NULL, ..., constraints = NULL)
slca(formula = NULL, ..., constraints = NULL)
formula |
a formula specifying the latent structure. Detailed model specification is provided under 'Details'. |
... |
additional formulae for defining the model structure. |
constraints |
a list of constraints for maintaining measurement invariance. Detailed explanation of applying constraints is available under 'Details'. |
The formula
can be broadly categorized into three main types, each serving a distinct purpose:
Defining Latent Class Variables with Manifest Indicators: Specify the relationship between a latent class variable and its manifest indicators. For example:
Defining Latent Class Variables with Manifest Indicators: Specify the relationship between a latent class variable and its manifest indicators. In these formulas, the latent class variable, denoted with square brackets or parentheses indicating the number of classes, is on the left-hand-side (lhs) and its manifest indicators are specified on right-hand-side (rhs). For example,
LC1[k] ~ x1 + x2 + x3 LC2[k] ~ y1 + y2 + y3 LC3(k) ~ z1 + z2 + z3
In these formulas, k
denotes the number of latent classes for the variable.
Relating Latent Class Variables to Each Other: Define relationships where one latent class variable is influenced by another. The subsequent example implies that LC2
is conditionally affected based on LC1
.
LC1 ~ LC2
Defining higher-level latent class variable: Identify latent class variables by other latent class variables rather than manifest indicators. Following example suggests that the P
is measured by LC1
, LC2
, and LC3
– all of which are latent class variables.
P[k] ~ LC1 + LC2 + LC3
In all types of the formula, variables specified on the left-hand side (lhs) influence those on the right-hand side (rhs).
The constraints
parameter allows you to enforce specific conditions on the model to ensure precise inference. For instance, in Longitudinal Latent Class Analysis (LTA), it's imperative that latent class variables across various time-points convey identical meanings. With the constraints
option, users can uphold measurement invariance in both the measurement and structural components of the model.
Measurement Invariance for Measurement Model: Ensures that probabilities associated with latent class variables are consistent, thus maintaining semantic meaning across classes.
c("LC1", "LC2", "LC3")
This command ensures that variables LC1
, LC2
, and LC3
are semantically consistent.
Measurement invariance for structural model: Applies constraints within the structural model to ensure consistent interpretations of transition probabilities.
c("P ~ LC1", "P -> LC2")
This command implies that the transition probabilities from P
to LC1
and from P
to LC2
are consistent.
An object of class slca
containing various components of the model:
tree
: A data.frame
that details the parent-child relationships among latent class and manifest variables.
latent
: A data.frame
listing all latent class variables with details on each.
measure
: A data.frame
that describes the measurement model.
struct
: A data.frame
that details the structural model.
The object prints model description with four part.
Latent variables: lists the latent class variables incorporated in the model, along with the number of classes for each variable. The root variable is marked by asterisk (*
).
Measurement model: Shows manifest indicators for each latent class variable and indicates measurement constraints (lowercase letters signify consistency).
Structural model: Describes conditional dependencies between latent class variables.
Dependency constraints: Outlines the constraints applied to the conditional dependencies between latent class variables. Each column marked with an uppercase alphabet symbolizes a consistent dependency structure.
# Standard LCA slca(lc[3] ~ y1 + y2 + y3) # Latent transition analysis (LTA) slca(l1[3] ~ y11 + y21 + y31, l2[3] ~ y12 + y22 + y32, l1 ~ l2) # LTA with measurement invariance slca(l1[3] ~ y11 + y21 + y31, l2[3] ~ y12 + y22 + y32, l1 ~ l2, constraints = c("l1", "l2")) # Joint latent class analysis slca(lx[3] ~ x1 + x2 + x3, ly[3] ~ y1 + y2 + y3, lz[3] ~ z1 + z2 + z3, jc[3] ~ lx + ly + lz) # Latent class profile analysis (with measurement invariance) slca(l1[3] ~ x1 + x2 + x3, l2[3] ~ y1 + y2 + y3, l3[3] ~ z1 + z2 + z3, pf[3] ~ lx + ly + lz, constraints = c("l1", "l2", "l3"))
# Standard LCA slca(lc[3] ~ y1 + y2 + y3) # Latent transition analysis (LTA) slca(l1[3] ~ y11 + y21 + y31, l2[3] ~ y12 + y22 + y32, l1 ~ l2) # LTA with measurement invariance slca(l1[3] ~ y11 + y21 + y31, l2[3] ~ y12 + y22 + y32, l1 ~ l2, constraints = c("l1", "l2")) # Joint latent class analysis slca(lx[3] ~ x1 + x2 + x3, ly[3] ~ y1 + y2 + y3, lz[3] ~ z1 + z2 + z3, jc[3] ~ lx + ly + lz) # Latent class profile analysis (with measurement invariance) slca(l1[3] ~ x1 + x2 + x3, l2[3] ~ y1 + y2 + y3, l3[3] ~ z1 + z2 + z3, pf[3] ~ lx + ly + lz, constraints = c("l1", "l2", "l3"))
Control Parameters for slca Estimation
slcaControl( em.iterlim = 5000, em.tol = 1e-08, nlm.iterlim = 1000, nlm.tol = 1e-10, init.param = NULL, nrep = 1, test.iter = 500, na.rm = FALSE, verbose = FALSE )
slcaControl( em.iterlim = 5000, em.tol = 1e-08, nlm.iterlim = 1000, nlm.tol = 1e-10, init.param = NULL, nrep = 1, test.iter = 500, na.rm = FALSE, verbose = FALSE )
em.iterlim |
an integer specifying maximum number of iterations allowed for EM algorithm. Default is 5000. |
em.tol |
a numeric value setting tolerance for the convergence of EM algorithm. Default is 1e-8. |
nlm.iterlim |
an integer specifying maximum number of iterations allowed for estimation with |
nlm.tol |
a numeric value setting tolerance for the convergence of |
init.param |
initial parameters. |
nrep |
number of trials. Default is 1. |
test.iter |
an integer specifying maximum number of iterations allowed for testing parameters. Default is 500 |
na.rm |
a logical value indicating whether to remove observations including missing values (NA) |
verbose |
a logical value indicating whether to display progress updates during the estimation process |
a list
with control parameters for slca estimation.