Lavaan Survey, multiple imputation and propensity score weighting

407 views
Skip to first unread message

JB

unread,
Jun 1, 2014, 8:55:31 PM6/1/14
to lav...@googlegroups.com
Dear Daniel,
First, many thanks for your package: survey facilities are a very useful feature!!
I am currently trying to use it for an application with propensity score matching.
Because of the missing data, I follow these steps:
1/ use multiple imputation first
2/ run a propensity score matching procedure for each data set to generate weights vectors (w), which thus vary for each imputed data sets.
3/ Then use lavaan survey with a following design:
design.ps <- svydesign(ids = ~1, weights = ~w, data = ImputedListWithWeights)
I found this line of code in McCaffrey 2004, "Propensity score estimation with boosted regression for evaluating causal effects in observational studies"
They use the package survey to perform the final analyses once they have generated their propensity scores
However, they do not use multiple imputation. Thus, my question is whether lavaan.survey will apply different weights in each data set as it should in this case (i.e., the w vector corresponding to the propensity score matching in this imputed data set)?
A minor question: after imputation, once I applied the
liss.implist <- lapply(seq(liss.imp$m), function(im) complete(liss.imp, im))
to get the list of imputed data sets, can I use directly lavaan.survey (it seems to work?) or do I need to apply:
library("mitools")
liss.implist <- imputationList(liss.implist)
I find that the resulting object is not as easy to manipulate so I would rather skip this bit if not necessary.
Best Regards and thanks a lot again!
JB

Message has been deleted

JB

unread,
Jun 2, 2014, 4:10:39 PM6/2/14
to lav...@googlegroups.com
PS: it seems that the imputationList() might be necessary after all.
I also tried to fit a lavaan model with 2 groups, and then apply the lavaan.survey command.
However, It produces the following error.
Error in FUN(X[[1L]], ...) : 
  dims [product 400] do not match the length of object [0]M

I want to do a group analysis with weights in lavaan.survey and then use predict() and the resulting object to get the factor scores (I will finally use the factor score to compute the effect size of the diff between the two groups). I used predict() with the fit object resulting from a runMI() call with two groups and I do get the factor scores in the two groups as desired. Would be awesome if I could do that using lavaan.survey (annoying reviewer asking for it...).
Best,
JB

Daniel Oberski

unread,
Jun 5, 2014, 4:20:59 AM6/5/14
to lav...@googlegroups.com
Hi Jean-Baptiste,


First, many thanks for your package: survey facilities are a very useful feature!!

Thanks for your support!  Paper can be found/cited as:

  Oberski, D. (2014). lavaan.survey: An R Package for
  Complex Survey Analysis of Structural Equation Models.
  Journal of Statistical Software, 57(1), 1-27. 



my question is whether lavaan.survey will apply different weights in each data set as it should in this case (i.e., the w vector corresponding to the propensity score matching in this imputed data set)?

Yes, the weight corresponding to each particular dataset will be used in the case of multiple imputation.
 

do I need to apply:
library("mitools")
liss.implist <- imputationList(liss.implist)

Yes, the survey package uses this standardized facility for multiple imputation and needs it to recognize multiply imputed data. 
 
I find that the resulting object is not as easy to manipulate

Note that liss.implist[[1]] is just the list of imputations, so no loss of manipulation abilities if you don't mind the [[1]]...

Daniel Oberski

unread,
Jun 5, 2014, 7:35:50 AM6/5/14
to lav...@googlegroups.com
Hi JB

Could you send me the code and data that reproduce this problem? I will take a look at it.

Best, Daniel

JB

unread,
Jun 5, 2014, 2:07:52 PM6/5/14
to lav...@googlegroups.com

 Dear Daniel,
Many Thanks for your comments, very useful and I will definitely cite your package!
I can't share the data but here is a commented syntax with the Demo.growth data, with the error I get in mine when I do lavaan.survey() with multiple group & imputation.
Best,
JB

library(lavaan)
library(lavaan.survey)
set.seed(12345)
#copy Demo.growth
Demo.growth1=Demo.growth

#create variable grouping based on values at t1
Demo.growth1$grouping=NA
Demo.growth1$grouping[Demo.growth1$t1>mean(Demo.growth1$t1)]=1
Demo.growth1$grouping[Demo.growth1$t1<=mean(Demo.growth1$t1)]=0
table(Demo.growth1$grouping)

#generate around 10% missing at t1-t4 (not not sure what I do is very elegant, but seems to work)
Demo.growth1$t1[sample(c(rep(1,9),0),400,replace=T)==0]=NA
Demo.growth1$t2[sample(c(rep(1,9),0),400,replace=T)==0]=NA
Demo.growth1$t3[sample(c(rep(1,9),0),400,replace=T)==0]=NA
Demo.growth1$t4[sample(c(rep(1,9),0),400,replace=T)==0]=NA

#generate artifical weights, as if 1 was treatment so all participatns in group 1 get weight 1 and the other 1 get weights around 3
Demo.growth1$w[Demo.growth1$grouping==1]=1
Demo.growth1$w[Demo.growth1$grouping==0]= rnorm(195,3,1)


#Without imputation (seems to run fine except for predict)
modelbase <- ' i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4
 s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4'
fit <- growth(modelbase, data=Demo.growth1,group="grouping")
summary(fit)
predict(fit)#here works fine, I get I and s for all complete cases in the two groups

design1 <- svydesign(ids = ~1, weights = ~w, data = Demo.growth1)
fitsurvey <- lavaan.survey(fit, design1)
summary(fitsurvey)
predict(fitsurvey)#does not work


#WITH IMPUTATION
#Prepare imputation
library(mice)
DataImp=mice(Demo.growth1,5)

#obtain list of imputed data sets
DataImpList <- lapply(seq(DataImp$m), FUN=function(NumDF) complete(DataImp, NumDF))

#fit model base
library(semTools)
fitI <- growth.mi(modelbase, data=DataImpList,group="grouping")
summary(fitI)
predict(fitI)#works, this time provides prediction for all cases, as based on multiple imputation


#create weights for all data sets
for (i in 1:length(DataImpList)) {
  DataImpList[[i]]$w[Demo.growth1$grouping==1]=1 
  DataImpList[[i]]$w[Demo.growth1$grouping==0]= rnorm(195,3,1)}
summary(DataImpList[[1]]$w) 

#transform list imputed data set for survey
library(mitools)
DataImpList <- imputationList(DataImpList) #this just changes the class of the list for lavaan.survey
#DataImpList[[1]]

designI <- svydesign(ids = ~1, weights = ~w, data = DataImpList)
fitsurveyI <- lavaan.survey(fitI, designI)#here is the ERROR message
#And below is what I would like to work
predict(fitsurveyI)

 

Daniel Oberski

unread,
Jun 6, 2014, 7:51:24 AM6/6/14
to lav...@googlegroups.com

This problem was due to a bug with the combination multiple group/multiple imputation. It has been fixed in a new development version 1.1.1 (on GitHub).

Factor scores for this multiple imputation/multiple group growth analysis, for the moment, can be obtained using this small trick:


fit.mi <- growth.mi(modelbase, data=DataImpList, group="grouping")

...

fit.growth <- growth(modelbase, data=Demo.growth1, group="grouping")

design.mi <- svydesign(ids = ~1, weights = ~w, data = DataImpList)

fit.survey <- lavaan.survey(fit.growth, design.mi)

fit.survey@Data <- fit.mi@Data # small trick to make predict work

predict(fit.survey) # gives factor scores for each group

Best, 
   Daniel

JB

unread,
Jun 6, 2014, 10:16:56 AM6/6/14
to lav...@googlegroups.com
Great!!! Many Thanks!
Reply all
Reply to author
Forward
0 new messages