Skip to content

erikson84/lavaanStan

Repository files navigation

lavaanStan

lavaanStan is a package designed to fit simple Bayesian SEM (Structural Equation Modeling) and CFA (Confirmatory Factor Analysis) written with lavaan syntax using precompiled Stan models.

Usage

lavaanStan works just like lavaan. Define a model using lavaan intuitive syntax and call lavaanStan function identifying the model type (CFA or SEM).

source(lavaanStan.R)

data("PoliticalDemocracy")
data <- PoliticalDemocracy
model <- '
   # latent variables
     ind60 =~ x1 + x2 + x3
     dem60 =~ y1 + y2 + y3 + y4
     dem65 =~ y5 + y6 + y7 + y8
   # regressions
     dem60 ~ ind60
     dem65 ~ ind60 + dem60
   # residual covariances
     y1 ~~ y5
     y2 ~~ y4 + y6
     y3 ~~ y7
     y4 ~~ y8
     y6 ~~ y8
'
fit <- lavaanStan(model=model, data=data, model.type='sem')
modelMatrix(fit, 'est')

Features

  • Multiple groups SEM and CFA;
  • MIMIC models (for model.type='sem' and fixed.x=TRUE);
  • User-defined equality constraints (including across groups);
  • Posterior predictive p-values based on simulated data $\chi^2$;
  • Model comparison available using LOO and WAIC (via loo package).

Not working yet

  • Latent growth models;
  • Joint or conditional modeling with observed exogenous variables (fixed.x=TRUE works!);
  • Categorical indicator variables;
  • Inequality constraints;
  • Custom priors (lavaanStan uses "default" weakly informative priors);
  • ...

Links

lavaan (News, tutorials and support for the lavaan package.)

blavaan (Another (much better and flexible) implementation of Bayesian SEM using lavaan syntax)

Stan (If you are here, Stan requires no introductions)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors