Hi folks,
I was experimenting with the auxiliary variables option in semtools and stumbled over this problem.
BTW, lavaan and semTools are fantastic pieces of software.
Using a trivial model with two observed variables and one auxiliary variable, I tried fitting:
a) a saturated correlates model by hand using lavaan only
b) using the fitpathaux command in semTools
c) a saturated correlates model by hand using Mplus
d) using the AUXILIARY ARE: command in Mplus
I get:
a) returns an error in solve,default(E), but returns parameter estimates (without standard errors though) that look correct
b) returns an error about "no slot name of "Cache""
c) works and recovers correct estimate - estimates are very similar to a), but standard errors are provided
d) works, yields the same results as c) and recovers the correct estimate with standard errors
Replication code is provided below (code does not include Mplus files).
I must be doing something wrong in my lavaan model syntax, otherwise I don't understand why it would report correct estimates, but not report standard errors.
I also don't know why Mplus seems to be able to produce SE's in this example.
Any help appreciated,
Felix
=======================================
set.seed(123)
n <- 1000
a <- rnorm(n,0,1)
b <- rnorm(n,0,1)
x <- .4*a + rnorm(n,0,.5)
mean(x)
lrx <- .4*a + .4*b + rnorm(n,0,.1)
rx <- ifelse(lrx < .3,1,0)
xobs <- ifelse(rx==0,NA,x)
mean(xobs,na.rm=TRUE)
datobs <- data.frame(a,b,xobs)
#saturated correlates by hand
#yields error
#
# Error in solve.default(E) :
# Lapack routine dgesv: system is exactly singular
# Warning message:
# In estimateVCOV(lavaanModel, samplestats = lavaanSampleStats, options = lavaanOptions, :
# lavaan WARNING: could not compute standard errors!
mymodel <- "xobs ~ a
xobs ~~ b
a ~~ b"
s1 <- sem(model=mymodel,data=datobs,meanstructure=TRUE,fixed.x=FALSE,missing="fiml",mimic="Mplus")
coef(s1)
mymodel2 <- "xobs ~ a"
#using aux function semtools
#yields error
#
# Error in slot(value, what) :
# no slot of name "Cache" for this object of class "lavaan"
fitpathaux <- sem.auxiliary(mymodel2, aux="b", data=datobs)
library(MplusAutomation)
prepareMplusData(datobs,"datobs.dat")
#Mplus works with both doing the "saturated correlates" approach by hand
#or by using the AUXILIARY ARE command
# and returns estimated mean of Xobs to be -.009 (reasonably close to the truth given the missing data)