paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 182 forks source link

latent variables/confirmatory factor analysis #304

Open jebyrnes opened 6 years ago

jebyrnes commented 6 years ago

In a structural equation modeling framework, we often define latent unmeasured variables with indicators. For example

library(lavaan)
data(PoliticalDemocracy)

mod <- 'ind60 =~ x1 + x2 + x3'

fit <- sem(mod, data=PoliticalDemocracy)

summary(fit)

produces loadings and variances

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  ind60 =~                                            
    x1                1.000                           
    x2                2.193    0.142   15.403    0.000
    x3                1.824    0.153   11.883    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .x1                0.084    0.020    4.140    0.000
   .x2                0.108    0.074    1.455    0.146
   .x3                0.468    0.091    5.124    0.000
    ind60             0.446    0.087    5.135    0.000

Note, the loading on ind60 -> x1 is fixed to 1 for identifiability by common convention. In this model, the model is fit to the covariance matrix of the data. Think of ind60 as causing, i.e., being a predictor of, all of its indicators.

Moreover, lavPredict can generate predicted factor scores, for example. In full SEMs, latent variables are later used just like any other variable - as predictors, as responses, etc.

Would it be possible to incorporate factor analysis or latent variables in general into brms?