cor_mat <- matrix(c(
1, 0.55, 0.30, 0.25,
0.55, 1, 0.35, 0.40,
0.30, 0.35, 1, 0.45,
0.25, 0.40, 0.45, 1
), nrow = 4, byrow = TRUE)
colnames(cor_mat) <- rownames(cor_mat) <- c(
"GeneralAbility",
"SchoolType",
"SES",
"Achievement"
)
model1 <- '
Achievement ~ GeneralAbility + SchoolType + SES
SES ~ GeneralAbility
SchoolType ~ GeneralAbility + SES
'
fit1_dummy <- sem(
model1,
sample.cov = cor_mat,
sample.nobs = 18058,
do.fit = FALSE
)
semPaths(
fit1_dummy,
layout = "tree",
what = "path",
intercepts = FALSE
)
fit1 <- sem(
model1,
sample.cov = cor_mat,
sample.nobs = 18058
)
summary(fit1, standardized = TRUE)
## lavaan 0.6-21 ended normally after 1 iteration
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 18058
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Achievement ~
## GeneralAbility -0.012 0.008 -1.516 0.129 -0.012 -0.012
## SchoolType 0.282 0.008 36.054 0.000 0.282 0.282
## SES 0.355 0.007 51.750 0.000 0.355 0.355
## SES ~
## GeneralAbility 0.300 0.007 42.261 0.000 0.300 0.300
## SchoolType ~
## GeneralAbility 0.489 0.006 77.168 0.000 0.489 0.489
## SES 0.203 0.006 32.081 0.000 0.203 0.203
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Achievement 0.730 0.008 95.021 0.000 0.730 0.730
## .SES 0.910 0.010 95.021 0.000 0.910 0.910
## .SchoolType 0.660 0.007 95.021 0.000 0.660 0.660
cov_mat <- matrix(c(
1.00, 0.70, 0.65, 0.50,
0.70, 1.00, 0.75, 0.55,
0.65, 0.75, 1.00, 0.60,
0.50, 0.55, 0.60, 1.00
), nrow = 4, byrow = TRUE)
colnames(cov_mat) <- rownames(cov_mat) <- c(
"Depression1",
"Depression2",
"Depression3",
"SocialActivity"
)
model2_marker <- '
PsychHealth =~ Depression1 + 1*Depression2 + Depression3 + SocialActivity
'
fit2_marker <- cfa(
model2_marker,
sample.cov = cov_mat,
sample.nobs = 6053
)
fitMeasures(fit2_marker, c("chisq", "df"))
## chisq df
## 200.113 3.000
model2_std <- '
PsychHealth =~ Depression1 + Depression2 + Depression3 + SocialActivity
'
fit2_std <- cfa(
model2_std,
sample.cov = cov_mat,
sample.nobs = 6053,
std.lv = TRUE
)
fitMeasures(fit2_std, c("chisq", "df"))
## chisq df
## 124.774 2.000
cov_mat2 <- matrix(c(
0.77, 0.38, 0.39, -0.25, 0.31, 0.24, -3.16, -0.92,
0.38, 0.65, 0.39, -0.32, 0.29, 0.25, -3.56, -0.88,
0.39, 0.39, 0.62, -0.27, 0.26, 0.19, -2.63, -0.72,
-0.25, -0.32, -0.27, 6.09, -0.36, -0.18, 6.09, 0.88,
0.31, 0.29, 0.26, -0.36, 7.67, 0.51, -3.12, -1.49,
0.24, 0.25, 0.19, -0.18, 0.51, 1.69, -4.58, -1.41,
-3.16, -3.56, -2.63, 6.09, -3.12, -4.58, 204.79, 16.53,
-0.92, -0.88, -0.72, 0.88, -1.49, -1.41, 16.53, 7.24
), nrow = 8, byrow = TRUE)
rownames(cov_mat2) <- colnames(cov_mat2) <- c(
"D1", "D2", "D3", "SA", "F", "CC", "PA", "PM"
)
model3 <- '
PsychHealth =~ D1 + D2 + D3 + SA
PhysicalHealth =~ F + CC + PA
PM ~ PsychHealth + PhysicalHealth
PsychHealth ~~ PhysicalHealth
PsychHealth ~~ 1*PsychHealth
PhysicalHealth ~~ 1*PhysicalHealth
'
fit3_dummy <- sem(
model3,
sample.cov = cov_mat2,
sample.nobs = 6053,
do.fit = FALSE
)
semPaths(
fit3_dummy,
layout = "tree",
what = "path",
intercepts = FALSE
)
fit3 <- sem(
model3,
sample.cov = cov_mat2,
sample.nobs = 6053
)
summary(fit3, standardized = TRUE)
## lavaan 0.6-21 ended normally after 40 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 16
##
## Number of observations 6053
##
## Model Test User Model:
##
## Test statistic 1208.056
## Degrees of freedom 20
## P-value (Chi-square) 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PsychHealth =~
## D1 1.000 1.000 0.862
## D2 0.760 0.009 84.181 0.000 0.760 0.825
## D3 0.740 0.009 83.764 0.000 0.740 0.822
## SA -0.580 0.033 -17.418 0.000 -0.580 -0.233
## PhysicalHealth =~
## F 1.000 1.000 0.349
## CC 0.692 0.019 37.284 0.000 0.692 0.518
## PA -8.255 0.206 -40.020 0.000 -8.255 -0.559
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PM ~
## PsychHealth 0.205 0.119 1.723 0.085 0.205 0.071
## PhysicalHealth -2.615 0.122 -21.357 0.000 -2.615 -0.906
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PsychHealth ~~
## PhysicalHealth 0.726 0.015 48.447 0.000 0.726 0.726
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PsychHealth 1.000 1.000 1.000
## PhysicalHealth 1.000 1.000 1.000
## .D1 0.345 0.010 34.277 0.000 0.345 0.256
## .D2 0.271 0.007 38.943 0.000 0.271 0.320
## .D3 0.262 0.007 39.257 0.000 0.262 0.324
## .SA 5.869 0.107 54.608 0.000 5.869 0.946
## .F 7.194 0.135 53.341 0.000 7.194 0.878
## .CC 1.306 0.027 47.494 0.000 1.306 0.732
## .PA 150.140 3.346 44.876 0.000 150.140 0.688
## .PM 2.234 0.195 11.472 0.000 2.234 0.268