Hi all,
I run into exactly the same error and I can't figure out what I am doing wrong. I created a snapshot of the data so that my error can be reproduced:
library(lavaan)
library(semTools)
data <- data.frame ( bls_math_err_8 = c(24, 6, 24, 22, NA, 16, 15, 15, 14, 9, 22, 15, 11, 17, 19, NA, 7, 13, NA, 19),
bls_read_word_err_8 = c(NA, 2, 3, 18, 48, 4, 16, NA, 11, 8, 0, 2, 48, 2, 1, 24, 15, 16, 7, 5),
bls_read_cont_err_8 = c(12, NA, 0, 156, 156, 10, NA, 27, 12, 6, 5, 0, 156, 10, 4, 112, 24, 20, 15, 11),
bls_pseudo_err_8 = c(13, 4, 14, 31, 8, NA, 14, 11, 12, 9, 8, NA, 31, 8, 6, 29, 17, 22, 14, 7),
GA = c(31, 32, 30, 30, 30, 35, 28, 33, 27, 30, 35, 26, 28, 30, 26, 32, NA, 31, 30, 33),
cntxt_adv_trans = c(-0.66, -0.66, -0.35, -0.66, 0.13, 1.33, -2.04, -0.09, -0.09, -0.35, -2.04, -1.07, -0.35, -2.04, 1.04, 1.60, NA, 0.34, 0.88, 2.64),
sex = c(1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1),
Group_Home_05 = c(NA, 1, 1, 1, NA, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0) )
model1 <- 'acad =~ bls_math_err_8 + bls_read_word_err_8 + bls_read_cont_err_8 + bls_pseudo_err_8
acad ~ GA + cntxt_adv_trans + GA:cntxt_adv_trans + sex + Group_Home_05 + Group_Home_05:GA
GA ~~ cntxt_adv_trans + 0*GA:cntxt_adv_trans + 0*sex + 0*Group_Home_05
cntxt_adv_trans ~~ 0*GA:cntxt_adv_trans + 0*sex + 0*Group_Home_05'
fit <- sem(model1, data=data, missing="fiml.x", fixed.x=FALSE)
(mylist <- list(GA=seq(23,42, by=1), Group_Home_05=1:0))
em.acad <- emmeans(fit, specs = ~ GA | Group_Home_05,
at = mylist,
# because SEMs can have multiple DVs:
lavaan.DV = "acad")
emmip(em.acad, Group_Home_05 ~ GA, at=mylist, CIs=TRUE)
em2 <- emmip(em.acad, Group_Home_05 ~ GA, at=mylist, CIs=TRUE, plotit=FALSE)
I get the following error when running emmeans() :
Error in names(temp_bhat) <- c(par_names, colnames(emmb$V)[!colnames(emmb$V) %in% :
'names' attribute [8] must be the same length as the vector [7]
Note: sem() also gives a warning about large variance for this small subset of the data, but I do not get this warning when running the code on my full database, so this is likely unrelated to the error above.
Any help would be greatly appreciated!
Best wishes,
Sabrina
Op vrijdag 24 november 2023 om 10:18:32 UTC schreef Terrence Jorgensen: