I am trying to set up a SEM with imputed data using lavaan/lavaan.mi so that I can next do genetic sensitivty analysis using Gsens. I had been using runMI but then read that it's better to use lavaan.mi instead.
In my data - MH is a binary variable (0,1) and I checked that it's coded as a factor. CF is a continuous variable, PGS is a continuous variable.
Here is my code to set up the a, b, and c paths and assign the variables from the data:
#path a
cf_pgs_p1<-'
CF ~ PGS
CF ~~ CF
CF ~ 1'
#path b
mh_pgs_p1 <- 'MH ~ PGS'
#path c
MH_CF<-'
MH ~ CF
'
#define MH=depression
for (i in 1:100) {
print(i)
imputed_list[[i]] <- transform(imputed_list[[i]], MH = depression)}
#define CF= zert_sad
for (i in 1:100) {
print(i)
imputed_list[[i]] <- transform(imputed_list[[i]], CF = zert_sad)}
#define PGS = AlsMDD_std_score_S0
for (i in 1:100) {
print(i)
imputed_list[[i]] <- transform(imputed_list[[i]], PGS = AlsMDD_std_score_S0)}
Setting up the models:
#b path
fit_b <- lavaan.mi(mh_pgs_p1,
data=imputed_list,
ordered = "MH",
estimator = "WLSMV"
)
r2_p1 <-summary(fit_b, rsquare=TRUE)[6,5]
mh_pgs_p1_r<-sqrt(r2_p1)
#c path
fit_c <- lavaan.mi(MH_CF,
data=imputed_list,
ordered = "MH",
estimator = "WLSMV"
)
r2<-summary(fit_c, rsquare=TRUE)[6,5]
MH_CF_r<-sqrt(r2)
#a path
fit_a<-lavaan.mi(cf_pgs_p1,
data=imputed_list
)
#the dimensions for getting R-squared are wrong here.
r2_a<-summary(fit_a,rsquare=TRUE)[6,5]
cf_pgs_p1_r<-sqrt(r2_a)
When I run each of the models with lavaan.mi() I get the below warning:
Warning message:
In semTools::runMI(model = mh_pgs_p1, data = imputed_list, ordered = "MH", :
The runMI() function and lavaan.mi-class have been deprecated and will cease to be included in future versions of semTools.
Support is still provided for analyzing lavaan.mi-class objects (e.g., compRelSEM() can estimate reliability using pooled results), which can now be created using the lavaan.mi package.
The deprecated runMI() function now creates an object of class OLDlavaan.mi, which can be analyzed using the deprecated functions in semTools, like lavTestLRT.mi(), that have been updated and improved in the lavaan.mi package.
Find more details help('semTools-deprecated)
Also, when I run summary(fit_b) and summary (fit_c) I get the below error message:
Error in cov(do.call(rbind, coefList)[, PT$free > 0L & !duplicated(PT$free)]) :
supply both 'x' and 'y' or a matrix-like 'x'
Summary(fit_a) works fine.
My questions are:
1. why am I still getting the warning if I am using lavaan.mi()
2. What is causing the error message when I try and get summary stats? I don't get any warnings/error (other than the one above) when running the model itself.