Error in names(temp_bhat) when using emmeans() on a lavaan() object

29 views Asked by At

I am running a path analysis in lavaan that looks like this:

 model <- '''
  DV ~ Covariate1 + Covariate2 + Covariate3 +
  Predictor0 + Predictor1 + Predictor2 + Predictor3 + Predictor4 +
  Predictor1:Predictor3 + Predictor1:Predictor4 + Predictor2:Predictor3 + Predictor2:Predictor4 +
  Predictor1:Covariate1 + Predictor2:Covariate1 + Predictor3:Covariate1 + Predictor4:Covariate1 +
  Predictor1 ~~ Covariate4
  Predictor2 ~~ Covariate4
  Predictor3 ~~ Covariate4
  Predictor4 ~~ Covariate4
  '''

model_fit <- sem(model, data = d, missing = "fiml", estimator = "MLR")

The model runs without problems. However, when I try to estimate marginal effects for the Predictor1×Covariate1 interaction using emmeans, I get an error:

Covariate1_range <- range(d$Covariate1)
Predictor1_range <- range(d$Predictor1)
  
model_fit_marg <- emmeans(
  model_fit,
  ~ Predictor1 | Covariate1,
  at = list(
    Covariate1 = Covariate1_range,
    Predictor1 = Predictor1_range
    ),
  data = d,
  lavaan.DV = "DV"
)
Error in names(temp_bhat) <- c(par_names, colnames(emmb$V)[!colnames(emmb$V) %in%  : 
  'names' attribute [21] must be the same length as the vector [17]

Note that Covariate1 is num [1:2] 0 1.

Hope you can save my day!

0

There are 0 answers