Learn R Programming

piecewiseSEM (version 1.1.1)

sem.lavaan: Constructs variance-covariance based SEM

Description

Estimates variance-covariance based (traditional) structural equation model (SEM) using the lavaan package.

Usage

sem.lavaan(modelList, data, compute.int = TRUE, corr.errors, add.vars, ...)

Arguments

modelList
a list of regressions representing the structural equation model.
data
a data.frame containing the full dataset for the SEM.
compute.int
a logical argument whether the interactions should be computed by hand. Default is TRUE.
corr.errors
a vector of variables with correlated errors (separated by "~~").
add.vars
a vector of additional variables whose independence claims should be evaluated, but which do not appear in the model list.
...
additional arguments passed to lavaan.

Value

  • Returns a model object of class lavaan.

Details

Interactions among numeric variables are computed by hand, appended to the original data.frame, and modified in the formulae passed to lavaan::sem.

References

Grace, James B. Structural equation modeling and natural systems. Cambridge University Press, 2006.

See Also

sem

Examples

Run this code
# Load example data
data(shipley2009)

# Load model packages
library(lme4)
library(nlme)

# Create list of models 
shipley2009.modlist = list(
  
  lme(DD ~ lat, random = ~1|site/tree, na.action = na.omit, 
      data = shipley2009),
  
  lme(Date ~ DD, random = ~1|site/tree, na.action = na.omit, 
      data = shipley2009),
  
  lme(Growth ~ Date, random = ~1|site/tree, na.action = na.omit, 
      data = shipley2009),
  
  glmer(Live ~ Growth+(1|site)+(1|tree), 
        family=binomial(link = "logit"), data = shipley2009) 
  
)
  
# Get variance-covariance based SEM
(lavaan.model = sem.lavaan(shipley2009.modlist, shipley2009))

lavaan::summary(lavaan.model)

### NOT RUN ###

# # Load data from Shipley (2013)
# data(shipley2013) 
# 
# shipley2013.modlist = list(
#   
#   lme(x2~x1, random = ~x1 | species, data = shipley2013),
#   
#   lme(x3~x2, random = ~x2 | species, data = shipley2013),
#   
#   lme(x4~x2, random = ~x2 | species, data = shipley2013),
#   
#   lme(x5~x3+x4, random = ~x3+x4 | species, data = shipley2013)
#   
# )
# 
# # Get variance-covariance based SEM
# lavaan::summary(sem.lavaan(shipley2013.modlist, shipley2013))

### END NOT RUN ###

Run the code above in your browser using DataLab