knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
knitr::opts_chunk$set(echo = TRUE) library(lavaan) library(semPlot)
A fully latent or full structural model has two parts:
Measurement model: the latent variable with it's measured variables (CFA)
Structural model: the relationship between other variables and the measurement model
The structural model may be a second order latent, like we did last week
knitr::include_graphics("pictures/full_sem2.png")
A reminder from earlier this semester:
Example of formative indicator
Other names people use for these:
knitr::include_graphics("pictures/indicators.png")
Identification rules of thumb:
2+ emitted paths rule
Parceling
Test each CFA piece separately to make sure they run.
Slowly add structural paths to see if you can get the full model to work.
As you add the structural components, you should not see a big change in the loadings to the indicators
modificationindices()
and other tricks to improve model fitWhat should the stopping rule be?
knitr::include_graphics("pictures/kline_model.png")
library(lavaan) library(semPlot) family.cor <- lav_matrix_lower2full(c(1.00, .74, 1.00, .27, .42, 1.00, .31, .40, .79, 1.00, .32, .35, .66, .59, 1.00)) family.sd <- c(32.94, 22.75, 13.39, 13.68, 14.38) rownames(family.cor) <- colnames(family.cor) <- names(family.sd) <- c("father", "mother", "famo", "problems", "intimacy") family.cov <- cor2cov(family.cor, family.sd)
family.model <- ' adjust =~ problems + intimacy family =~ father + mother + famo'
family.fit <- cfa(model = family.model, sample.cov = family.cov, sample.nobs = 203)
inspect(family.fit, "cov.lv") inspect(family.fit, "cor.lv")
family.fit <- cfa(model = family.model, sample.cov = family.cor, sample.nobs = 203)
summary(family.fit, rsquare = TRUE, standardized = TRUE, fit.measures = TRUE)
modificationindices(family.fit, sort = T)
family.model2 <- ' adjust =~ problems + intimacy family =~ father + mother + famo father ~~ mother' family.fit2 <- cfa(model = family.model2, sample.cov = family.cov, sample.nobs = 203) inspect(family.fit2, "cor.lv")
semPaths(family.fit, whatLabels="std", layout="tree", edge.label.cex = 1)
predict.model <- ' adjust =~ problems + intimacy family =~ father + mother + famo adjust~family'
predict.fit <- sem(model = predict.model, sample.cov = family.cor, sample.nobs = 203)
summary(predict.fit, rsquare = TRUE, standardized = TRUE, fit.measures = TRUE)
semPaths(predict.fit, whatLabels="std", layout="tree", edge.label.cex = 1)
knitr::include_graphics("pictures/full_example.png")
family.cor <- lav_matrix_lower2full(c(1.00, .42, 1.00, -.43, -.50, 1.00, -.39, -.43, .78, 1.00, -.24, -.37, .69, .73, 1.00, -.31, -.33, .63, .87, .72, 1.00, -.25, -.25, .49, .53, .60, .59, 1.00, -.25, -.26, .42, .42, .44, .45, .77, 1.00, -.16, -.18, .23, .36, .38, .38, .59, .58, 1.00)) family.sd <- c(13.00, 13.50, 13.10, 12.50, 13.50, 14.20, 9.50, 11.10, 8.70) rownames(family.cor) <- colnames(family.cor) <- names(family.sd) <- c("parent_psych","low_SES","verbal", "reading","math","spelling","motivation","harmony","stable") family.cov <- cor2cov(family.cor, family.sd)
=~
to define a latent variable that predicts manifest variables.<~
to create a composite variable that is predicted by the manifest variables. composite.model <- ' risk <~ low_SES + parent_psych + verbal achieve =~ reading + math + spelling adjustment =~ motivation + harmony + stable risk =~ achieve + adjustment '
composite.fit <- sem(model = composite.model, sample.cov = family.cov, sample.nobs = 158)
summary(composite.fit, rsquare = TRUE, standardized = TRUE, fit.measures = TRUE)
modificationindices(composite.fit, sort = T)
semPaths(composite.fit, whatLabels="std", layout="tree", edge.label.cex = 1)
In this lecture you've learned:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.