Rich Jones, Doug Tommet
July 9, 2022
These are the packages used by R for these examples
address <- "https://lvmworkshop.s3.amazonaws.com/LDA/ex0201.dat"
msq0201 <- read_csv(address,
col_names=c("msqtot1", "msqtot4", "msqtot7", "age", "black"))
msq0201 <- msq0201 %>%
mutate(msqtot1 = case_when(msqtot1 == -9999 ~ NA_real_,
TRUE ~ msqtot1),
msqtot4 = case_when(msqtot4 == -9999 ~ NA_real_,
TRUE ~ msqtot4),
msqtot7 = case_when(msqtot7 == -9999 ~ NA_real_,
TRUE ~ msqtot7),
cage = age - mean(age, na.rm = TRUE),
cblack = black - mean(black, na.rm = TRUE),
usedata = !(is.na(msqtot1) & is.na(msqtot4) & is.na(msqtot7)))
Characteristic | N = 14,4561 |
---|---|
msqtot1 | |
0 | 96 (0.7%) |
1 | 213 (1.6%) |
2 | 578 (4.2%) |
3 | 1,136 (8.3%) |
4 | 2,609 (19%) |
5 | 4,293 (31%) |
6 | 4,773 (35%) |
Unknown | 758 |
msqtot4 | |
0 | 127 (1.2%) |
1 | 234 (2.1%) |
2 | 474 (4.3%) |
3 | 942 (8.6%) |
4 | 1,865 (17%) |
5 | 3,437 (32%) |
6 | 3,820 (35%) |
Unknown | 3,557 |
msqtot7 | |
0 | 163 (2.0%) |
1 | 204 (2.5%) |
2 | 405 (5.0%) |
3 | 756 (9.3%) |
4 | 1,637 (20%) |
5 | 2,528 (31%) |
6 | 2,476 (30%) |
Unknown | 6,287 |
age | |
67 | 4,457 (31%) |
72 | 3,970 (27%) |
77 | 2,872 (20%) |
82 | 1,878 (13%) |
87 | 1,279 (8.8%) |
black | |
0 | 11,666 (81%) |
1 | 2,790 (19%) |
cage | |
-7.07802988378528 | 4,457 (31%) |
-2.07802988378528 | 3,970 (27%) |
2.92197011621472 | 2,872 (20%) |
7.92197011621472 | 1,878 (13%) |
12.9219701162147 | 1,279 (8.8%) |
cblack | |
-0.192999446596569 | 11,666 (81%) |
0.807000553403431 | 2,790 (19%) |
usedata | |
FALSE | 397 (2.7%) |
TRUE | 14,059 (97%) |
1
n (%)
|
## lavaan 0.6-12 ended normally after 40 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 8
##
## Used Total
## Number of observations 14059 14456
## Number of missing patterns 7
##
## Model Test User Model:
## Standard Robust
## Test Statistic 60.866 55.213
## Degrees of freedom 1 1
## P-value (Chi-square) 0.000 0.000
## Scaling correction factor 1.102
## Yuan-Bentler correction (Mplus variant)
##
## Model Test Baseline Model:
##
## Test statistic 6609.379 5149.872
## Degrees of freedom 3 3
## P-value 0.000 0.000
## Scaling correction factor 1.283
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.991 0.989
## Tucker-Lewis Index (TLI) 0.973 0.968
##
## Robust Comparative Fit Index (CFI) 0.991
## Robust Tucker-Lewis Index (TLI) 0.973
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -52691.657 -52691.657
## Scaling correction factor 1.311
## for the MLR correction
## Loglikelihood unrestricted model (H1) -52661.224 -52661.224
## Scaling correction factor 1.288
## for the MLR correction
##
## Akaike (AIC) 105399.315 105399.315
## Bayesian (BIC) 105459.723 105459.723
## Sample-size adjusted Bayesian (BIC) 105434.300 105434.300
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.065 0.062
## 90 Percent confidence interval - lower 0.052 0.049
## 90 Percent confidence interval - upper 0.080 0.076
## P-value RMSEA <= 0.05 0.031 0.058
##
## Robust RMSEA 0.065
## 90 Percent confidence interval - lower 0.051
## 90 Percent confidence interval - upper 0.080
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.018 0.018
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## i =~
## msqtot1 1.000
## msqtot4 1.000
## msqtot7 1.000
## s =~
## msqtot1 0.000
## msqtot4 0.600
## msqtot7 1.200
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## i ~~
## s -0.013 0.036 -0.375 0.708
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|)
## .msqtot1 0.000
## .msqtot4 0.000
## .msqtot7 0.000
## i 4.785 0.011 448.650 0.000
## s -0.309 0.013 -24.007 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .msqtot1 0.620 0.033 18.979 0.000
## .msqtot4 0.807 0.019 42.801 0.000
## .msqtot7 0.691 0.043 16.106 0.000
## i 1.001 0.037 27.001 0.000
## s 0.435 0.054 8.000 0.000
ex0201mod.mplus <- mplusObject(
ANALYSIS = "ESTIMATOR = MLR; ",
MODEL = "[msqtot1-msqtot7@0] ;
msqtot1-msqtot7*;
i by msqtot1@1 msqtot4@1 msqtot7@1 ;
s by msqtot1@0 msqtot4@.6 msqtot7@1.2 ;
[i* s*];
i* s*;
i with s* ;",
OUTPUT = "STDYX; tech1;",
usevariables = c("msqtot1", "msqtot4", "msqtot7"),
rdata = msq0201
)
ex0201fit.mplus <- mplusModeler(ex0201mod.mplus,
dataout = "ex0201.dat",
modelout = "ex0201.inp",
run = TRUE)
##
## Running model: ex0201.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0201.inp"
## Reading model: ex0201.out
## [1] TRUE
## Reading model: ex0201.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 8
##
## Model: Chi2(df = 1) = 55.212, p = 0
## Baseline model: Chi2(df = 3) = 5149.828, p = 0
##
## Fit Indices:
##
## CFI = 0.989, TLI = 0.968, SRMR = 0.024
## RMSEA = 0.062, 90% CI [0.049, 0.077], p < .05 = 0.067
## AIC = 105399.315, BIC = 105459.723
## NULL
## Reading model: ex0201.out
## paramHeader param est se est_se pval
## 1 I.BY MSQTOT1 1.000 0.000 999.000 999.000
## 2 I.BY MSQTOT4 1.000 0.000 999.000 999.000
## 3 I.BY MSQTOT7 1.000 0.000 999.000 999.000
## 4 S.BY MSQTOT1 0.000 0.000 999.000 999.000
## 5 S.BY MSQTOT4 0.600 0.000 999.000 999.000
## 6 S.BY MSQTOT7 1.200 0.000 999.000 999.000
## 7 I.WITH S -0.013 0.036 -0.375 0.708
## 8 Means I 4.785 0.011 448.648 0.000
## 9 Means S -0.309 0.013 -24.007 0.000
## 10 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 11 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 12 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 13 Variances I 1.001 0.037 27.000 0.000
## 14 Variances S 0.435 0.054 8.000 0.000
## 15 Residual.Variances MSQTOT1 0.620 0.033 18.979 0.000
## 16 Residual.Variances MSQTOT4 0.807 0.019 42.800 0.000
## 17 Residual.Variances MSQTOT7 0.691 0.043 16.106 0.000
## Reading model: ex0201.out
## $parameterSpecification
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 0 0
## MSQTOT4 0 0
## MSQTOT7 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 1 NA NA
## MSQTOT4 0 2 NA
## MSQTOT7 0 0 3
##
## $alpha
## I S
## 1 4 5
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 6 NA
## S 7 8
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $startingValues
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 1 0.0
## MSQTOT4 1 0.6
## MSQTOT7 1 1.2
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 0.81 NA NA
## MSQTOT4 0.00 0.911 NA
## MSQTOT7 0.00 0.000 1.016
##
## $alpha
## I S
## 1 0 0
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 0.05 NA
## S 0.00 0.05
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
## lavaan 0.6-12 ended normally after 49 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 12
##
## Number of observations 14059
## Number of missing patterns 7
##
## Model Test User Model:
##
## Test statistic 84.140
## Degrees of freedom 3
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 9121.331
## Degrees of freedom 9
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.991
## Tucker-Lewis Index (TLI) 0.973
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -51447.318
## Loglikelihood unrestricted model (H1) -51405.248
##
## Akaike (AIC) 102918.636
## Bayesian (BIC) 103009.248
## Sample-size adjusted Bayesian (BIC) 102971.113
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.044
## 90 Percent confidence interval - lower 0.036
## 90 Percent confidence interval - upper 0.052
## P-value RMSEA <= 0.05 0.885
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.014
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## i =~
## msqtot1 1.000 1.003 0.789
## msqtot4 1.000 1.003 0.714
## msqtot7 1.000 1.003 0.657
## s =~
## msqtot1 0.000 0.000 0.000
## msqtot4 0.600 0.399 0.284
## msqtot7 1.200 0.798 0.523
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## i ~
## cage -0.046 0.002 -29.205 0.000 -0.046 -0.294
## cblack -0.708 0.025 -28.044 0.000 -0.705 -0.280
## s ~
## cage -0.032 0.002 -15.725 0.000 -0.049 -0.308
## cblack -0.108 0.029 -3.683 0.000 -0.163 -0.065
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .i ~~
## .s -0.071 0.032 -2.198 0.028 -0.121 -0.121
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .msqtot1 0.000 0.000 0.000
## .msqtot4 0.000 0.000 0.000
## .msqtot7 0.000 0.000 0.000
## .i 4.783 0.010 472.759 0.000 4.767 4.767
## .s -0.357 0.012 -29.035 0.000 -0.537 -0.537
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .msqtot1 0.613 0.029 20.869 0.000 0.613 0.378
## .msqtot4 0.808 0.017 48.451 0.000 0.808 0.409
## .msqtot7 0.688 0.035 19.695 0.000 0.688 0.295
## .i 0.847 0.030 28.129 0.000 0.841 0.841
## .s 0.399 0.046 8.619 0.000 0.902 0.902
ex0202mod.mplus <- mplusObject(
ANALYSIS = "ESTIMATOR = MLR; ",
MODEL = "[msqtot1-msqtot7@0] ;
msqtot1-msqtot7*;
i by msqtot1@1 msqtot4@1 msqtot7@1 ;
s by msqtot1@0 msqtot4@.6 msqtot7@1.2 ;
[i* s*];
i* s*;
i with s* ;
i s on cage cblack ; ",
OUTPUT = "STDYX; tech1;",
usevariables = c("msqtot1", "msqtot4", "msqtot7", "cage", "cblack"),
rdata = msq0201
)
ex0202fit.mplus <- mplusModeler(ex0202mod.mplus,
dataout = "ex0202.dat",
modelout = "ex0202.inp",
run = TRUE)
##
## Running model: ex0202.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0202.inp"
## Reading model: ex0202.out
## [1] TRUE
## Reading model: ex0202.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 12
##
## Model: Chi2(df = 3) = 74.766, p = 0
## Baseline model: Chi2(df = 9) = 7494.404, p = 0
##
## Fit Indices:
##
## CFI = 0.99, TLI = 0.971, SRMR = 0.022
## RMSEA = 0.041, 90% CI [0.033, 0.05], p < .05 = 0.958
## AIC = 102918.636, BIC = 103009.248
## NULL
## Reading model: ex0202.out
## paramHeader param est se est_se pval
## 1 I.BY MSQTOT1 1.000 0.000 999.000 999.000
## 2 I.BY MSQTOT4 1.000 0.000 999.000 999.000
## 3 I.BY MSQTOT7 1.000 0.000 999.000 999.000
## 4 S.BY MSQTOT1 0.000 0.000 999.000 999.000
## 5 S.BY MSQTOT4 0.600 0.000 999.000 999.000
## 6 S.BY MSQTOT7 1.200 0.000 999.000 999.000
## 7 I.ON CAGE -0.046 0.002 -25.802 0.000
## 8 I.ON CBLACK -0.708 0.028 -25.199 0.000
## 9 S.ON CAGE -0.032 0.002 -14.355 0.000
## 10 S.ON CBLACK -0.108 0.032 -3.338 0.001
## 11 I.WITH S -0.070 0.034 -2.061 0.039
## 12 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 13 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 14 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 15 Intercepts I 4.783 0.010 470.588 0.000
## 16 Intercepts S -0.357 0.013 -27.045 0.000
## 17 Residual.Variances MSQTOT1 0.613 0.031 19.581 0.000
## 18 Residual.Variances MSQTOT4 0.808 0.018 44.943 0.000
## 19 Residual.Variances MSQTOT7 0.688 0.040 17.311 0.000
## 20 Residual.Variances I 0.847 0.034 24.804 0.000
## 21 Residual.Variances S 0.399 0.051 7.827 0.000
## Reading model: ex0202.out
## $parameterSpecification
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 2 NA NA NA
## MSQTOT7 0 0 3 NA NA
## CAGE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 4 5 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 6 7
## S 0 0 8 9
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 10 NA NA NA
## S 11 12 NA NA
## CAGE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $startingValues
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 1 0.0 0 0
## MSQTOT4 1 0.6 0 0
## MSQTOT7 1 1.2 0 0
## CAGE 0 0.0 1 0
## CBLACK 0 0.0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CAGE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 0 0 -0.146 0.003
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 0.05 NA NA NA
## S 0.00 0.05 NA NA
## CAGE 0.00 0.00 40.275 NA
## CBLACK 0.00 0.00 -0.087 0.158
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
msq0201 <- msq0201 %>%
mutate(id = row_number()) %>%
group_by(id) %>%
mutate(age.new1 = case_when(age==67 ~ sample(c(65:69), 1),
age==72 ~ sample(c(70:74), 1),
age==77 ~ sample(c(75:79), 1),
age==82 ~ sample(c(80:84), 1),
age==87 ~ sample(c(85:89), 1)),
age.new4 = age.new1 + 3,
age.new7 = age.new1 + 6) %>%
ungroup() %>%
mutate(age1 = (age.new1 - mean(age.new1, na.rm = TRUE))/5,
age4 = (age.new4 - mean(age.new1, na.rm = TRUE))/5,
age7 = (age.new7 - mean(age.new1, na.rm = TRUE))/5)
address <- "https://lvmworkshop.s3.amazonaws.com/LDA/ex0203.dat"
msq0203 <- read_csv(address, col_names=c("msqtot1", "msqtot4", "msqtot7",
"age1", "age4", "age7", "male", "black"))
msq0203 <- msq0203 %>%
mutate(msqtot1 = case_when(msqtot1 == -9999 ~ NA_real_,
TRUE ~ msqtot1),
msqtot4 = case_when(msqtot4 == -9999 ~ NA_real_,
TRUE ~ msqtot4),
msqtot7 = case_when(msqtot7 == -9999 ~ NA_real_,
TRUE ~ msqtot7),
cmale = male - mean(male, na.rm = TRUE),
cblack = black - mean(black, na.rm = TRUE)
)
Lavaan currently can not use tscores
ex0203mod.mplus <- mplusObject(
VARIABLE = "TSCORES = age1 age4 age7; ",
ANALYSIS = "ESTIMATOR = MLR;
Type = RANDOM;",
MODEL = "i s | msqtot1 msqtot4 msqtot7 AT age1 age4 age7 ;
i s on cmale cblack ; ",
OUTPUT = "STDYX; tech1;",
usevariables = c("msqtot1", "msqtot4", "msqtot7",
"age1", "age4", "age7", "cmale", "cblack"),
rdata = msq0203
)
ex0203fit.mplus <- mplusModeler(ex0203mod.mplus,
dataout = "ex0203.dat",
modelout = "ex0203.inp",
run = TRUE)
##
## Running model: ex0203.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0203.inp"
## Reading model: ex0203.out
## [1] TRUE
## Reading model: ex0203.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 12
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 102664.366, BIC = 102754.978
## NULL
## Reading model: ex0203.out
## paramHeader param est se est_se pval
## 1 I.ON CMALE 0.081 0.018 4.479 0.000
## 2 I.ON CBLACK -0.725 0.026 -27.715 0.000
## 3 S.ON CMALE 0.049 0.014 3.414 0.001
## 4 S.ON CBLACK -0.056 0.019 -2.937 0.003
## 5 S.WITH I 0.107 0.008 12.782 0.000
## 6 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 7 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 8 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 9 Intercepts I 4.775 0.009 518.792 0.000
## 10 Intercepts S -0.265 0.007 -40.645 0.000
## 11 Residual.Variances MSQTOT1 0.752 0.017 44.612 0.000
## 12 Residual.Variances MSQTOT4 0.787 0.019 42.237 0.000
## 13 Residual.Variances MSQTOT7 0.949 0.028 34.422 0.000
## 14 Residual.Variances I 0.621 0.021 29.370 0.000
## 15 Residual.Variances S 0.083 0.010 8.540 0.000
## Reading model: ex0203.out
## $parameterSpecification
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CMALE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 2 NA NA NA
## MSQTOT7 0 0 3 NA NA
## CMALE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CMALE CBLACK
## 1 4 5 0 0
##
## $beta
## I S CMALE CBLACK
## I 0 0 6 7
## S 0 0 8 9
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CMALE CBLACK
## I 10 NA NA NA
## S 11 12 NA NA
## CMALE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $startingValues
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CMALE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CMALE 0 0 1 0
## CBLACK 0 0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CMALE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CMALE CBLACK
## 1 4.93 -0.297 0 0
##
## $beta
## I S CMALE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CMALE CBLACK
## I 1.52 NA NA NA
## S 0.00 1.587 NA NA
## CMALE 0.00 0.000 0.118 NA
## CBLACK 0.00 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
Lavaan currently can not use tscores
ex0204mod.mplus <- mplusObject(
VARIABLE = "TSCORES = age1 age4 age7; ",
ANALYSIS = "ESTIMATOR = MLR;
Type = RANDOM;",
MODEL = "i s q | msqtot1 msqtot4 msqtot7 AT age1 age4 age7 ;
i s q on cmale cblack ;
msqtot1-msqtot7 (1) ;
q@0; ",
OUTPUT = "STDYX; tech1;",
SAVEDATA = "save = fscores; file = fscores0204.dat;",
usevariables = c("msqtot1", "msqtot4", "msqtot7",
"age1", "age4", "age7",
"cmale", "cblack"),
rdata = msq0203
)
ex0204fit.mplus <- mplusModeler(ex0204mod.mplus,
dataout = "ex0204.dat",
modelout = "ex0204.inp",
run = TRUE)
##
## Running model: ex0204.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0204.inp"
## Reading model: ex0204.out
## [1] TRUE
## Reading model: ex0204.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 13
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 102274.35, BIC = 102372.514
## NULL
## Reading model: ex0204.out
## paramHeader param est se est_se pval
## 1 I.ON CMALE 0.086 0.021 4.045 0.000
## 2 I.ON CBLACK -0.689 0.031 -22.447 0.000
## 3 S.ON CMALE 0.024 0.015 1.578 0.115
## 4 S.ON CBLACK -0.052 0.020 -2.541 0.011
## 5 Q.ON CMALE -0.002 0.009 -0.178 0.859
## 6 Q.ON CBLACK -0.027 0.011 -2.426 0.015
## 7 S.WITH I 0.123 0.008 15.638 0.000
## 8 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 9 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 10 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 11 Intercepts I 4.883 0.011 463.956 0.000
## 12 Intercepts S -0.206 0.007 -28.149 0.000
## 13 Intercepts Q -0.085 0.004 -19.379 0.000
## 14 Residual.Variances MSQTOT1 0.793 0.012 68.148 0.000
## 15 Residual.Variances MSQTOT4 0.793 0.012 68.148 0.000
## 16 Residual.Variances MSQTOT7 0.793 0.012 68.148 0.000
## 17 Residual.Variances I 0.615 0.021 29.828 0.000
## 18 Residual.Variances S 0.090 0.009 9.584 0.000
## 19 Residual.Variances Q 0.000 0.000 999.000 999.000
## Reading model: ex0204.out
## $parameterSpecification
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S Q CMALE CBLACK
## MSQTOT1 0 0 0 0 0
## MSQTOT4 0 0 0 0 0
## MSQTOT7 0 0 0 0 0
## CMALE 0 0 0 0 0
## CBLACK 0 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 1 NA NA NA
## MSQTOT7 0 0 1 NA NA
## CMALE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S Q CMALE CBLACK
## 1 2 3 4 0 0
##
## $beta
## I S Q CMALE CBLACK
## I 0 0 0 5 6
## S 0 0 0 7 8
## Q 0 0 0 9 10
## CMALE 0 0 0 0 0
## CBLACK 0 0 0 0 0
##
## $psi
## I S Q CMALE CBLACK
## I 11 NA NA NA NA
## S 12 13 NA NA NA
## Q 0 0 0 NA NA
## CMALE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $startingValues
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S Q CMALE CBLACK
## MSQTOT1 0 0 0 0 0
## MSQTOT4 0 0 0 0 0
## MSQTOT7 0 0 0 0 0
## CMALE 0 0 0 1 0
## CBLACK 0 0 0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CMALE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S Q CMALE CBLACK
## 1 4.958 -0.273 -0.318 0 0
##
## $beta
## I S Q CMALE CBLACK
## I 0 0 0 0 0
## S 0 0 0 0 0
## Q 0 0 0 0 0
## CMALE 0 0 0 0 0
## CBLACK 0 0 0 0 0
##
## $psi
## I S Q CMALE CBLACK
## I 1.504 NA NA NA NA
## S 0.000 5.568 NA NA NA
## Q 0.000 0.000 0 NA NA
## CMALE 0.000 0.000 0 0.118 NA
## CBLACK 0.000 0.000 0 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
ex0204.savedata <- readModels("ex0204.out")[["savedata"]] %>%
as_tibble() %>%
mutate(ID = row_number())
## Reading model: ex0204.out
ex0204.savedata <- ex0204.savedata %>%
mutate(py1 = I + S*AGE1 + Q*(AGE1^2),
py4 = I + S*AGE4 + Q*(AGE4^2),
py7 = I + S*AGE7 + Q*(AGE7^2))
ex0204.savedata.long <- ex0204.savedata %>%
pivot_longer(c(AGE1:AGE7, py1:py7), names_to = "year", values_to = "value") %>%
separate(year,c("label", "year"), sep= -1) %>%
arrange(ID, year) %>%
pivot_wider(names_from = label, values_from = value) %>%
select(ID, year, AGE, py) %>%
mutate(year = as.numeric(year),
ID = factor(ID))
ex0204.savedata.long %>%
sample_frac(.1, replace = FALSE) %>%
ggplot(aes(x = AGE, y = py, group = ID, color = ID)) +
geom_line() +
labs(title = "MSQ Total Score by year",
x = "Age", y = "Predicted MSQ") +
guides(color = "none")
address <- "https://lvmworkshop.s3.amazonaws.com/LDA/ex0205.dat"
msq0205 <- read_csv(address, col_names=c("msqtot1", "msqtot4", "msqtot7",
"age1", "age4", "age7", "male",
"black", "id"))
msq0205 <- msq0205 %>%
mutate(msqtot1 = case_when(msqtot1 == -9999 ~ NA_real_,
TRUE ~ msqtot1),
msqtot4 = case_when(msqtot4 == -9999 ~ NA_real_,
TRUE ~ msqtot4),
msqtot7 = case_when(msqtot7 == -9999 ~ NA_real_,
TRUE ~ msqtot7),
cmale = male - mean(male, na.rm = TRUE),
cblack = black - mean(black, na.rm = TRUE)
)
Lavaan currently can not use tscores
ex0205mod.mplus <- mplusObject(
VARIABLE = "TSCORES = age1 age4 age7;
IDVARIABLE = id ;",
ANALYSIS = "ESTIMATOR = MLR;
Type = RANDOM;",
MODEL = "i s | msqtot1 msqtot4 msqtot7 AT age1 age4 age7 ;
i s on cmale cblack ;
msqtot1-msqtot7 ;",
OUTPUT = "STDYX; tech1;",
SAVEDATA = "save = fscores; file = fscores0205.dat;",
usevariables = c("msqtot1", "msqtot4", "msqtot7",
"age1", "age4", "age7", "cmale", "cblack", "id"),
rdata = msq0205
)
ex0205fit.mplus <- mplusModeler(ex0205mod.mplus,
dataout = "ex0205.dat",
modelout = "ex0205.inp",
run = TRUE)
##
## Running model: ex0205.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0205.inp"
## Reading model: ex0205.out
## [1] TRUE
## Reading model: ex0205.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 12
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 102664.366, BIC = 102754.978
## NULL
## Reading model: ex0205.out
## paramHeader param est se est_se pval
## 1 I.ON CMALE 0.081 0.018 4.479 0.000
## 2 I.ON CBLACK -0.725 0.026 -27.715 0.000
## 3 S.ON CMALE 0.049 0.014 3.414 0.001
## 4 S.ON CBLACK -0.056 0.019 -2.937 0.003
## 5 S.WITH I 0.107 0.008 12.782 0.000
## 6 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 7 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 8 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 9 Intercepts I 4.775 0.009 518.792 0.000
## 10 Intercepts S -0.265 0.007 -40.645 0.000
## 11 Residual.Variances MSQTOT1 0.752 0.017 44.612 0.000
## 12 Residual.Variances MSQTOT4 0.787 0.019 42.237 0.000
## 13 Residual.Variances MSQTOT7 0.949 0.028 34.422 0.000
## 14 Residual.Variances I 0.621 0.021 29.370 0.000
## 15 Residual.Variances S 0.083 0.010 8.540 0.000
## Reading model: ex0205.out
## $parameterSpecification
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CMALE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 2 NA NA NA
## MSQTOT7 0 0 3 NA NA
## CMALE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CMALE CBLACK
## 1 4 5 0 0
##
## $beta
## I S CMALE CBLACK
## I 0 0 6 7
## S 0 0 8 9
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CMALE CBLACK
## I 10 NA NA NA
## S 11 12 NA NA
## CMALE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $startingValues
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CMALE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CMALE 0 0 1 0
## CBLACK 0 0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CMALE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CMALE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CMALE CBLACK
## 1 4.93 -0.297 0 0
##
## $beta
## I S CMALE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CMALE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CMALE CBLACK
## I 1.52 NA NA NA
## S 0.00 1.587 NA NA
## CMALE 0.00 0.000 0.118 NA
## CBLACK 0.00 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
## Reading model: ex0205.out
ex0205.savedata <- ex0205.savedata %>%
mutate(py1 = I + S*AGE1,
py4 = I + S*AGE4,
py7 = I + S*AGE7)
ex0205.savedata.long <- ex0205.savedata %>%
pivot_longer(c(MSQTOT1:MSQTOT7, AGE1:AGE7, py1:py7),
names_to = "year", values_to = "value") %>%
separate(year,c("label", "year"), sep= -1) %>%
arrange(ID, year) %>%
pivot_wider(names_from = label, values_from = value) %>%
select(ID, year, MSQTOT, AGE, py) %>%
mutate(year = as.numeric(year),
ID = factor(ID))
summary(ex0205.savedata.long[,c("MSQTOT", "py")])
## MSQTOT py
## Min. :0.000 Min. :-0.1823
## 1st Qu.:4.000 1st Qu.: 4.2026
## Median :5.000 Median : 4.8346
## Mean :4.707 Mean : 4.6078
## 3rd Qu.:6.000 3rd Qu.: 5.2928
## Max. :6.000 Max. : 5.8616
## NA's :9411
## MSQTOT py
## MSQTOT 1.0000000 0.8520618
## py 0.8520618 1.0000000
Lavaan currently doesn’t do mixture models
ex0206mod.mplus <- mplusObject(
VARIABLE = "CLASSES = c(2) ; ",
ANALYSIS = "ESTIMATOR = MLR;
TYPE = MIXTURE ;",
MODEL = "%OVERALL%
i s | msqtot1@0 msqtot4@.6 msqtot7@1.2 ;
%c#1%
msqtot1-msqtot7 (1) ;
[i s];
i s;
%c#2%
msqtot1-msqtot7 (2) ;
[i s];
i s;",
OUTPUT = "STDYX; tech1; tech11; tech14;",
usevariables = c("msqtot1", "msqtot4", "msqtot7"),
rdata = msq0201
)
ex0206fit.mplus <- mplusModeler(ex0206mod.mplus,
dataout = "ex0206.dat",
modelout = "ex0206.inp",
run = TRUE)
##
## Running model: ex0206.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0206.inp"
## Reading model: ex0206.out
## [1] TRUE
## Reading model: ex0206.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 12
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 98730.721, BIC = 98821.333
## NULL
## Reading model: ex0206.out
## paramHeader param est se est_se pval
## 1 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 2 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 3 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 4 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 5 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 6 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 7 S.WITH I 0.018 0.026 0.681 0.496
## 8 Means I 4.028 0.075 53.523 0.000
## 9 Means S -0.457 0.082 -5.547 0.000
## 10 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 11 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 12 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 13 Variances I 0.610 0.046 13.316 0.000
## 14 Variances S 0.493 0.048 10.259 0.000
## 15 Residual.Variances MSQTOT1 1.280 0.073 17.539 0.000
## 16 Residual.Variances MSQTOT4 1.280 0.073 17.539 0.000
## 17 Residual.Variances MSQTOT7 1.280 0.073 17.539 0.000
## 18 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 19 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 20 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 21 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 22 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 23 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 24 S.WITH I 0.018 0.026 0.681 0.496
## 25 Means I 5.502 0.084 65.887 0.000
## 26 Means S -0.172 0.042 -4.154 0.000
## 27 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 28 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 29 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 30 Variances I 0.041 0.043 0.946 0.344
## 31 Variances S 0.075 0.018 4.095 0.000
## 32 Residual.Variances MSQTOT1 0.336 0.037 9.048 0.000
## 33 Residual.Variances MSQTOT4 0.336 0.037 9.048 0.000
## 34 Residual.Variances MSQTOT7 0.336 0.037 9.048 0.000
## 35 Means C#1 -0.072 0.207 -0.349 0.727
## LatentClass
## 1 1
## 2 1
## 3 1
## 4 1
## 5 1
## 6 1
## 7 1
## 8 1
## 9 1
## 10 1
## 11 1
## 12 1
## 13 1
## 14 1
## 15 1
## 16 1
## 17 1
## 18 2
## 19 2
## 20 2
## 21 2
## 22 2
## 23 2
## 24 2
## 25 2
## 26 2
## 27 2
## 28 2
## 29 2
## 30 2
## 31 2
## 32 2
## 33 2
## 34 2
## 35 Categorical.Latent.Variables
## Reading model: ex0206.out
## $parameterSpecification
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 0 0
## MSQTOT4 0 0
## MSQTOT7 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 1 NA NA
## MSQTOT4 0 1 NA
## MSQTOT7 0 0 1
##
## $alpha
## I S
## 1 2 3
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 4 NA
## S 5 6
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 0 0
## MSQTOT4 0 0
## MSQTOT7 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 7 NA NA
## MSQTOT4 0 7 NA
## MSQTOT7 0 0 7
##
## $alpha
## I S
## 1 8 9
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 10 NA
## S 5 11
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $alpha.c
## C#1 C#2
## 1 12 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## $startingValues
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 1 0.0
## MSQTOT4 1 0.6
## MSQTOT7 1 1.2
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 0.81 NA NA
## MSQTOT4 0.00 0.911 NA
## MSQTOT7 0.00 0.000 1.016
##
## $alpha
## I S
## 1 4.948 -0.406
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 1.247 NA
## S 0.000 2.157
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7
## 1 0 0 0
##
## $lambda
## I S
## MSQTOT1 1 0.0
## MSQTOT4 1 0.6
## MSQTOT7 1 1.2
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7
## MSQTOT1 0.81 NA NA
## MSQTOT4 0.00 0.911 NA
## MSQTOT7 0.00 0.000 1.016
##
## $alpha
## I S
## 1 4.948 -0.406
##
## $beta
## I S
## I 0 0
## S 0 0
##
## $psi
## I S
## I 1.247 NA
## S 0.000 2.157
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $alpha.c
## C#1 C#2
## 1 0 0
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
Lavaan currently doesn’t do mixture models
ex0207mod.mplus <- mplusObject(
VARIABLE = "CLASSES = c(2) ; ",
ANALYSIS = "TYPE = MIXTURE ;
STARTS = 40 8;",
MODEL = "%OVERALL%
i s | msqtot1@0 msqtot4@.6 msqtot7@1.2 ;
c#1 on cage cblack ;
%c#1%
msqtot1-msqtot7 (1) ;
[i s];
i s;
%c#2%
msqtot1-msqtot7 (2) ;
[i s];
i s;",
OUTPUT = "STDYX; tech1; tech11; tech14;",
usevariables = c("msqtot1", "msqtot4", "msqtot7", "cage", "cblack"),
rdata = msq0201
)
ex0207fit.mplus <- mplusModeler(ex0207mod.mplus,
dataout = "ex0207.dat",
modelout = "ex0207.inp",
run = TRUE)
##
## Running model: ex0207.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0207.inp"
## Reading model: ex0207.out
## [1] TRUE
## Reading model: ex0207.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 14
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 97022.341, BIC = 97128.055
## NULL
## Reading model: ex0207.out
## paramHeader param est se est_se pval
## 1 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 2 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 3 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 4 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 5 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 6 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 7 S.WITH I -0.006 0.012 -0.551 0.582
## 8 Means I 5.404 0.019 285.510 0.000
## 9 Means S -0.143 0.015 -9.369 0.000
## 10 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 11 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 12 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 13 Variances I 0.092 0.013 7.120 0.000
## 14 Variances S 0.092 0.017 5.259 0.000
## 15 Residual.Variances MSQTOT1 0.389 0.012 31.377 0.000
## 16 Residual.Variances MSQTOT4 0.389 0.012 31.377 0.000
## 17 Residual.Variances MSQTOT7 0.389 0.012 31.377 0.000
## 18 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 19 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 20 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 21 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 22 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 23 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 24 S.WITH I -0.006 0.012 -0.551 0.582
## 25 Means I 3.932 0.029 134.413 0.000
## 26 Means S -0.591 0.035 -17.018 0.000
## 27 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 28 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 29 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 30 Variances I 0.628 0.037 17.133 0.000
## 31 Variances S 0.439 0.048 9.108 0.000
## 32 Residual.Variances MSQTOT1 1.385 0.033 41.668 0.000
## 33 Residual.Variances MSQTOT4 1.385 0.033 41.668 0.000
## 34 Residual.Variances MSQTOT7 1.385 0.033 41.668 0.000
## 35 C#1.ON CAGE -0.129 0.005 -27.124 0.000
## 36 C#1.ON CBLACK -1.620 0.067 -24.292 0.000
## 37 Intercepts C#1 0.371 0.063 5.892 0.000
## LatentClass
## 1 1
## 2 1
## 3 1
## 4 1
## 5 1
## 6 1
## 7 1
## 8 1
## 9 1
## 10 1
## 11 1
## 12 1
## 13 1
## 14 1
## 15 1
## 16 1
## 17 1
## 18 2
## 19 2
## 20 2
## 21 2
## 22 2
## 23 2
## 24 2
## 25 2
## 26 2
## 27 2
## 28 2
## 29 2
## 30 2
## 31 2
## 32 2
## 33 2
## 34 2
## 35 Categorical.Latent.Variables
## 36 Categorical.Latent.Variables
## 37 Categorical.Latent.Variables
## Reading model: ex0207.out
## $parameterSpecification
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 1 NA NA NA
## MSQTOT7 0 0 1 NA NA
## CAGE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 2 3 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 4 NA NA NA
## S 5 6 NA NA
## CAGE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 7 NA NA NA NA
## MSQTOT4 0 7 NA NA NA
## MSQTOT7 0 0 7 NA NA
## CAGE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 8 9 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 10 NA NA NA
## S 5 11 NA NA
## CAGE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $gamma.c
## CAGE CBLACK
## C#1 13 14
## C#2 0 0
##
## $alpha.c
## C#1 C#2
## 1 12 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## $startingValues
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 1 0.0 0 0
## MSQTOT4 1 0.6 0 0
## MSQTOT7 1 1.2 0 0
## CAGE 0 0.0 1 0
## CBLACK 0 0.0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CAGE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 4.948 -0.406 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 1.247 NA NA NA
## S 0.000 2.157 NA NA
## CAGE 0.000 0.000 20.138 NA
## CBLACK 0.000 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 1 0.0 0 0
## MSQTOT4 1 0.6 0 0
## MSQTOT7 1 1.2 0 0
## CAGE 0 0.0 1 0
## CBLACK 0 0.0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CAGE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 4.948 -0.406 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 1.247 NA NA NA
## S 0.000 2.157 NA NA
## CAGE 0.000 0.000 20.138 NA
## CBLACK 0.000 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $gamma.c
## CAGE CBLACK
## C#1 0 0
## C#2 0 0
##
## $alpha.c
## C#1 C#2
## 1 0 0
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## attr(,"class")
## [1] "mplus.tech1" "list"
Lavaan currently doesn’t do mixture models
ex0208mod.mplus <- mplusObject(
VARIABLE = "CLASSES = c(2) ; ",
ANALYSIS = "TYPE = MIXTURE ;
STARTS = 40 8;",
MODEL = "%OVERALL%
i s | msqtot1@0 msqtot4@.6 msqtot7@1.2 ;
i s on cage cblack ;
c#1 on cage cblack ;
%c#1%
msqtot1-msqtot7 (1) ;
[i s];
i s;
i s on cage cblack ;
%c#2%
msqtot1-msqtot7 (2) ;
[i s];
i s;
i s on cage cblack ;",
OUTPUT = "STDYX; tech1; tech11; tech14;",
usevariables = c("msqtot1", "msqtot4", "msqtot7", "cage", "cblack"),
rdata = msq0201
)
ex0208fit.mplus <- mplusModeler(ex0208mod.mplus,
dataout = "ex0208.dat",
modelout = "ex0208.inp",
run = TRUE)
##
## Running model: ex0208.inp
## System command: cd "/Users/douglastommet/Dropbox/work/ShortCourse/POSTED/SLIDES/LDA/lavaan" && "/Applications/Mplus/mplus" "ex0208.inp"
## Reading model: ex0208.out
## [1] TRUE
## Reading model: ex0208.out
## Estimated using MLR
## Number of obs: 14059, number of (free) parameters: 22
##
## Fit Indices:
##
## CFI = NA, TLI = NA, SRMR = NA
## RMSEA = NA, 90% CI [NA, NA], p < .05 = NA
## AIC = 96416.34, BIC = 96582.462
## NULL
## Reading model: ex0208.out
## paramHeader param est se est_se pval
## 1 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 2 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 3 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 4 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 5 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 6 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 7 I.ON CAGE -0.039 0.003 -13.027 0.000
## 8 I.ON CBLACK -0.539 0.046 -11.596 0.000
## 9 S.ON CAGE -0.037 0.005 -8.146 0.000
## 10 S.ON CBLACK -0.153 0.057 -2.706 0.007
## 11 S.WITH I 0.010 0.017 0.588 0.557
## 12 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 13 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 14 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 15 Intercepts I 4.119 0.041 100.652 0.000
## 16 Intercepts S -0.488 0.053 -9.184 0.000
## 17 Residual.Variances MSQTOT1 1.311 0.055 23.915 0.000
## 18 Residual.Variances MSQTOT4 1.311 0.055 23.915 0.000
## 19 Residual.Variances MSQTOT7 1.311 0.055 23.915 0.000
## 20 Residual.Variances I 0.486 0.038 12.684 0.000
## 21 Residual.Variances S 0.336 0.042 7.959 0.000
## 22 I.| MSQTOT1 1.000 0.000 999.000 999.000
## 23 I.| MSQTOT4 1.000 0.000 999.000 999.000
## 24 I.| MSQTOT7 1.000 0.000 999.000 999.000
## 25 S.| MSQTOT1 0.000 0.000 999.000 999.000
## 26 S.| MSQTOT4 0.600 0.000 999.000 999.000
## 27 S.| MSQTOT7 1.200 0.000 999.000 999.000
## 28 I.ON CAGE 0.000 0.002 -0.149 0.882
## 29 I.ON CBLACK -0.225 0.048 -4.717 0.000
## 30 S.ON CAGE -0.015 0.002 -6.261 0.000
## 31 S.ON CBLACK 0.085 0.040 2.134 0.033
## 32 S.WITH I 0.010 0.017 0.588 0.557
## 33 Intercepts MSQTOT1 0.000 0.000 999.000 999.000
## 34 Intercepts MSQTOT4 0.000 0.000 999.000 999.000
## 35 Intercepts MSQTOT7 0.000 0.000 999.000 999.000
## 36 Intercepts I 5.470 0.055 99.722 0.000
## 37 Intercepts S -0.194 0.028 -6.935 0.000
## 38 Residual.Variances MSQTOT1 0.342 0.024 14.082 0.000
## 39 Residual.Variances MSQTOT4 0.342 0.024 14.082 0.000
## 40 Residual.Variances MSQTOT7 0.342 0.024 14.082 0.000
## 41 Residual.Variances I 0.051 0.027 1.847 0.065
## 42 Residual.Variances S 0.076 0.016 4.657 0.000
## 43 C#1.ON CAGE 0.080 0.007 10.995 0.000
## 44 C#1.ON CBLACK 0.954 0.079 12.120 0.000
## 45 Intercepts C#1 -0.101 0.146 -0.693 0.488
## LatentClass
## 1 1
## 2 1
## 3 1
## 4 1
## 5 1
## 6 1
## 7 1
## 8 1
## 9 1
## 10 1
## 11 1
## 12 1
## 13 1
## 14 1
## 15 1
## 16 1
## 17 1
## 18 1
## 19 1
## 20 1
## 21 1
## 22 2
## 23 2
## 24 2
## 25 2
## 26 2
## 27 2
## 28 2
## 29 2
## 30 2
## 31 2
## 32 2
## 33 2
## 34 2
## 35 2
## 36 2
## 37 2
## 38 2
## 39 2
## 40 2
## 41 2
## 42 2
## 43 Categorical.Latent.Variables
## 44 Categorical.Latent.Variables
## 45 Categorical.Latent.Variables
## Reading model: ex0208.out
## $parameterSpecification
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 1 NA NA NA NA
## MSQTOT4 0 1 NA NA NA
## MSQTOT7 0 0 1 NA NA
## CAGE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 2 3 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 4 5
## S 0 0 6 7
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 8 NA NA NA
## S 9 10 NA NA
## CAGE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 0 0 0 0
## MSQTOT4 0 0 0 0
## MSQTOT7 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 11 NA NA NA NA
## MSQTOT4 0 11 NA NA NA
## MSQTOT7 0 0 11 NA NA
## CAGE 0 0 0 0 NA
## CBLACK 0 0 0 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 12 13 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 14 15
## S 0 0 16 17
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 18 NA NA NA
## S 9 19 NA NA
## CAGE 0 0 0 NA
## CBLACK 0 0 0 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $gamma.c
## CAGE CBLACK
## C#1 21 22
## C#2 0 0
##
## $alpha.c
## C#1 C#2
## 1 20 0
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
##
## attr(,"class")
## [1] "mplus.parameterSpecification" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## $startingValues
## $LATENT.CLASS.1
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 1 0.0 0 0
## MSQTOT4 1 0.6 0 0
## MSQTOT7 1 1.2 0 0
## CAGE 0 0.0 1 0
## CBLACK 0 0.0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CAGE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 4.948 -0.406 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 1.247 NA NA NA
## S 0.000 2.157 NA NA
## CAGE 0.000 0.000 20.138 NA
## CBLACK 0.000 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.2
## $nu
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## 1 0 0 0 0 0
##
## $lambda
## I S CAGE CBLACK
## MSQTOT1 1 0.0 0 0
## MSQTOT4 1 0.6 0 0
## MSQTOT7 1 1.2 0 0
## CAGE 0 0.0 1 0
## CBLACK 0 0.0 0 1
##
## $theta
## MSQTOT1 MSQTOT4 MSQTOT7 CAGE CBLACK
## MSQTOT1 0.81 NA NA NA NA
## MSQTOT4 0.00 0.911 NA NA NA
## MSQTOT7 0.00 0.000 1.016 NA NA
## CAGE 0.00 0.000 0.000 0 NA
## CBLACK 0.00 0.000 0.000 0 0
##
## $alpha
## I S CAGE CBLACK
## 1 4.948 -0.406 0 0
##
## $beta
## I S CAGE CBLACK
## I 0 0 0 0
## S 0 0 0 0
## CAGE 0 0 0 0
## CBLACK 0 0 0 0
##
## $psi
## I S CAGE CBLACK
## I 1.247 NA NA NA
## S 0.000 2.157 NA NA
## CAGE 0.000 0.000 20.138 NA
## CBLACK 0.000 0.000 0.000 0.079
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## $LATENT.CLASS.REGRESSION.MODEL.PART
## $gamma.c
## CAGE CBLACK
## C#1 0 0
## C#2 0 0
##
## $alpha.c
## C#1 C#2
## 1 0 0
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
##
## attr(,"class")
## [1] "mplus.startingValues" "list"
## attr(,"group.names")
## [1] "LATENT.CLASS.1" "LATENT.CLASS.2"
## [3] "LATENT.CLASS.REGRESSION.MODEL.PART"
##
## attr(,"class")
## [1] "mplus.tech1" "list"