Created factors with EFA, tried regressing (lm) with control variables - Error message "variable lengths differ"

45 views Asked by At

EFA first-timer here!

I ran an Exploratory Factor Analysis (EFA) on a data set ("df1" = 1320 observations) with 50 variables by creating a subset with relevant variables only that have no missing values ("df2" = 301 observations). I was able to filter 4 factors (19 variables in total).

Now I would like to take those 4 factors and regress them with control variables.

For instance: Factor 1 (df2$fa1) describes job satisfaction. I would like to control for age and marital status.

Fa1Regression <- lm(df2$fa1 ~ df1$age + df1$marital)

However I receive the error message:

Error in model.frame.default(formula = df2$fa1 ~ df1$age +  : 
  variable lengths differ (found for 'df1$age')

What can I do to run the regression correctly? Can I delete observations from df1 that are nonexistent in df2 so that the variable lengths are the same?

1

There are 1 answers

1
Joe Razo On BEST ANSWER

Its having a problem using lm to regress a latent factor on other coefficients. Instead, use the lavaan package, where your model statement would be myModel<- 'df2$fa1~ x1+x2+x3'