I am using the mice
and semTools
packages to impute missing data for my SEM dataset. However, the summary()
only gives me unstandardized coefficients, but I like to have p-values and fit indices.
For this I first create a set of 15 imputed datasets like so:
library(mice)
library(semTools)
imp <- mice(indiv.sem, method = "pmm", m = 15, seed = 1234)
Then I load my SEM model:
# Latent factors
ses =~ educat + asset_index + urban
risk_lifestyle =~ smoke + heavy + inactive + gad2
risk_body =~ m19 + bmi_cat2
# Direct effect of socioeconomic status on knowledge
high_knowl ~ ses
risk_lifestyle ~ high_knowl
risk_body ~ high_knowl
# Direct effects of risk factors on clinical outcomes
clin_dm ~ risk_lifestyle + risk_body + clin_htn
clin_htn ~ risk_lifestyle + risk_body
# Direct effects of age and sex
ses ~ age + female
risk_lifestyle ~ age + female
risk_body ~ age + female
clin_dm ~ age + female
clin_htn ~ age + female
'
Then I try to run my analysis on the imputed data. I tried:
pooled_model <- sem.mi(model, data = imp, estimator = "MLM")
pooled_model <- semTools::runMI(model, data = imp,
m = 15, fun = "sem",
estimator = "MLM")
and
mice.imp<-NULL
for(i in 1:15) mice.imp[[i]]<-complete(imp,action=i,inc=FALSE)
pooled_model <-runMI(model,data=imp,fun="sem",estimator="MLM",orthogonal=TRUE,mimic="Mplus",
FUN=function(fit){list(wrmr=lavaan::fitMeasures(fit,"wrmr"))})
When using summary(pooled_model)
it only shows me est.ave. When trying
summary(pooled_model, fit.measures = TRUE, standardized = TRUE)
it gives me: Error in .local(object, ...) :
unused arguments (fit.measures = TRUE, standardized = TRUE)
When trying to extract coefficients and fit indices manually I get:
fitMeasures(pooled_model)
Error in getMethod("coef", "lavaan.mi") :
no method found for function 'coef' and signature lavaan.mi
parameterEstimates(pooled_model, standardized = TRUE)
gives me std.lv std.all std.nox only
I did install all newest package versions as suggested here , but the issue still persists. I also tried this with educat, asset_index as categorical variables/factors and age as agegroup, but this did not work either. I loaded no other packages to avoid any incompatibility between packages. The summary function works as intended when using it without the imputed dataset. Any help is hugely appreciated. Thank you in advance
for this simulated dataset:
set.seed(123)
indiv.sem <- data.frame(
smoke = sample(0:20, 200, replace = TRUE),
heavy = sample(0:1, 200, replace = TRUE, prob = c(0.7, 0.3)),
educat = sample(1:3, 200, replace = TRUE, prob = c(0.3, 0.5, 0.2)),
high_knowl = sample(0:1, 200, replace = TRUE, prob = c(0.4, 0.6)),
clin_htn = sample(0:1, 200, replace = TRUE, prob = c(0.3, 0.7)),
clin_dm = sample(c(0, 1, NA), 200, replace = TRUE, prob = c(0.6, 0.3, 0.1)),
age = sample(45:90, 200, replace = TRUE),
female = sample(0:1, 200, replace = TRUE, prob = c(0.5, 0.5)),
urban = sample(0:1, 200, replace = TRUE, prob = c(0.3, 0.7)),
bmi_cat2 = sample(0:1, 200, replace = TRUE, prob = c(0.4, 0.6)),
m19 = round(runif(200, 60, 130), 1),
asset_index = sample(c(1:5, NA), 200, replace = TRUE, prob = c(0.2, 0.2, 0.2, 0.2, 0.1, 0.1)),
inactive = sample(c(0, 1, NA), 200, replace = TRUE, prob = c(0.6, 0.3, 0.1)),
gad2 = sample(0:1, 200, replace = TRUE, prob = c(0.7, 0.3)),
agegroup = sample(c(1:4, NA), 200, replace = TRUE, prob = c(0.2, 0.3, 0.3, 0.1, 0.1))
)
I am using R4.4.2, and the semTools 0.5-6 from lavaan 0.6-19