auxiliary variables for missing data in lavaan, semtools, and Mplus

283 views
Skip to first unread message

Felix Thoemmes

unread,
Mar 28, 2013, 3:12:29 PM3/28/13
to lav...@googlegroups.com
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)

Alex Schoemann

unread,
Mar 28, 2013, 10:16:44 PM3/28/13
to lav...@googlegroups.com
Hmmmm. When I updated lavaan (0.5-12) and semTools (0.3-2) on my machine (running R 2.15.2) both models ran without warnings or errors and produced identical estimates.

-Alex

Felix Thoemmes

unread,
Mar 28, 2013, 11:25:28 PM3/28/13
to lav...@googlegroups.com
Indeed - on my home laptop the lavaan model works fine after updating.
Must have been a problem with previous versions.
Will try tomorrow on the office PC, but clearly the problem must lie
with some version conflicts.
Thanks Alex!
Felix
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "lavaan" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/lavaan/fRzYD-eS2ZY/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> lavaan+un...@googlegroups.com.
> To post to this group, send email to lav...@googlegroups.com.
> Visit this group at http://groups.google.com/group/lavaan?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages