knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
knitr::opts_chunk$set(echo = TRUE)
library(lavaan)
library(semPlot)

Full Structural Models

Example Model

knitr::include_graphics("pictures/full_sem2.png")

Full Structural Models

Full Structural Models

Example Model

knitr::include_graphics("pictures/indicators.png")

Identification

Structural Model Identification

Things to Consider

How to Model

How to Model

When to Stop?

Example Model

knitr::include_graphics("pictures/kline_model.png")

Example Model: Setup

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)

Example Model: Build the CFA

Example Model: Build the CFA

family.model <- '
adjust =~ problems + intimacy
family =~ father + mother + famo'

Example Model: Analyze the CFA

family.fit <- cfa(model = family.model,
                  sample.cov = family.cov,
                  sample.nobs = 203)

Example Model: Deal with Error

inspect(family.fit, "cov.lv")
inspect(family.fit, "cor.lv")

Example Model: Analyze the CFA

family.fit <- cfa(model = family.model,
                  sample.cov = family.cor,
                  sample.nobs = 203)

Example Model: Summarize the Model

summary(family.fit, 
        rsquare = TRUE, 
        standardized = TRUE,
        fit.measures = TRUE)

Example Model: Improve the Model?

modificationindices(family.fit, sort = T)

Example Model: Improve the Model?

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

Example Model: Diagram the Model

semPaths(family.fit, 
         whatLabels="std", 
         layout="tree", 
         edge.label.cex = 1)

Example Model: Build Full SEM

predict.model <- '
adjust =~ problems + intimacy
family =~ father + mother + famo
adjust~family'

Example Model: Analyze Full SEM

predict.fit <- sem(model = predict.model,
                   sample.cov = family.cor,
                   sample.nobs = 203)

Example Model: Summarize Full SEM

summary(predict.fit, 
        rsquare = TRUE, 
        standardized = TRUE,
        fit.measures = TRUE)

Example Model: Diagram Full SEM

semPaths(predict.fit, 
         whatLabels="std", 
         layout="tree", 
         edge.label.cex = 1)

Example 2: Composite Variables

knitr::include_graphics("pictures/full_example.png")

Example 2: Setup

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)

Example 2: Build the Model

Example 2: Build the Model

composite.model <- '
risk <~ low_SES + parent_psych + verbal
achieve =~ reading + math + spelling
adjustment =~ motivation + harmony + stable
risk =~ achieve + adjustment
'

Example 2: Analyze the Model

composite.fit <- sem(model = composite.model, 
                      sample.cov = family.cov, 
                      sample.nobs = 158)

Example 2: Summarize the Model

summary(composite.fit, 
        rsquare = TRUE, 
        standardized = TRUE,
        fit.measures = TRUE)

Example 2: Improve the Model?

modificationindices(composite.fit, sort = T)

Example 2: Diagram the Model

semPaths(composite.fit, 
         whatLabels="std", 
         layout="tree",
         edge.label.cex = 1)

Summary



doomlab/learnSEM documentation built on Jan. 25, 2024, 2 p.m.