Search code examples
rr-lavaanstructural-equation-model

lavaan: Define factor by multiple variables as in Mplus


I want to reduce typing-load in lavaan.

Imagine that you have 50 manisfest variables: var1, var2, var3, ... var50. In Mplus it is possible to assign a multitude of variables to a factor with the minus '-' sign like this:

Factor BY var1-var50;

Basically saying that Factor is defined by all 50 variables.

Is there a similar way to define the factor in lavaan? It seems that I need to state all 50 variable names:

model <- ' factor =~ var1 + var2 + var3 + var4 and so on...

Solution

  • Try this :

    lvmodel <- 
    paste('factor',paste(paste0('var',1:50),collapse='+'),sep='=~')