[R] Problems bootstrapping multigroup SEM
Chad Danyluck
c.danyluck at gmail.com
Tue Sep 2 21:29:04 CEST 2014
Dear John,
Thank you for your insights. I think you do understand what I've been
trying to do. Because I am doing a multigroup comparison – specifically,
examining the moderating role of test type on outcome – I needed two
covariance matrices to pass through the model. I wasn't sure how to do this
other than by listing these covariance matrices together. This list was
called to the SEM and worked when the summary stats were called. As you
point out, however, the covariance matrix did not get passed into bootSem()
because, rather than use the cov function, I simply added the list. On
further reflection, the crux of my problem, or confusion, seems to stem
from not understanding how to deal with the need to pass two covariance
matrices into bootSem(). I could pass
"cov(na.omit(stereotype.MAP.data[,-1],
na.omit(evaluative.MAP.data[,-1])))", but I thought that the two matrices
needed to be kept separate because I am comparing the models produced by
each matrix to one another.
Another problem comes to light as I think through the help documentation:
"In the case of an msem (i.e., multi-group) model, *a list of data sets
(again in the appropriate form), one for each group*; in this case,
bootstrapping is done within each group, treating the groups as strata.
Note that the original observations are required, not just the covariance
matrix of the observed variables in the model. *The default is the data set
stored in the sem object*, which will be present only if the model was fit
to a data set rather than to a covariance or moment matrix, and may not be
in a form suitable for Cov."
In my case, the data passed through the sem object was
"c(nrow(stereotype.MAP.data), nrow(evaluative.MAP.data))". Perhaps this is
not suitable for Cov?
At this point I am spinning my wheels. Any further suggestions would be
appreciated.
Kind regards,
Chad
On Wed, Aug 27, 2014 at 6:59 PM, John Fox <jfox at mcmaster.ca> wrote:
> Dear Chad,
>
> It's possible that I don't understand properly what you've done, but it
> appears as if you're passing to bootSem() the covariance matrices for the
> observed data rather than the case-by-variable data sets themselves. That's
> also what you say you're doing, and it's what the error message says.
>
> Moreover, if you look at the documentation in ?bootSem, you'll is that the
> Cov argument isn't a covariance matrix, but "a function to compute the
> input covariance or moment matrix; the default is cov. Use cor if the model
> is fit to the correlation matrix. The function hetcor in the polycor
> package will compute product-moment, polychoric, and polyserial
> correlations among mixed continuous and ordinal variables (see the first
> example below for an illustration)."
>
> So what is there to bootstrap if bootSem() doesn't have access to the
> original data sets? I suppose that one could do a parametric bootstrap of
> some sort, but that's not what bootSem() does -- in implements a
> nonoparametric bootstrap, which requires the original data.
>
> I hope this helps,
> John
>
> -----------------------------------------------
> John Fox, Professor
> McMaster University
> Hamilton, Ontario, Canada
> http://socserv.socsci.mcmaster.ca/jfox/
>
>
>
> > -----Original Message-----
> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> > project.org] On Behalf Of Chad Danyluck
> > Sent: Wednesday, August 27, 2014 12:22 PM
> > To: r-help at r-project.org
> > Subject: [R] Problems bootstrapping multigroup SEM
> >
> > Hello,
> >
> > I am having difficulty resolving an error I receive trying to bootstrap
> > a
> > multigroup SEM. The error (below) indicates that the model called to
> > bootSem doesn't contain matrices. This is true, sort of, because I
> > created
> > a list of two covariance matrices for the model to call. All of this
> > syntax
> > works fine (a summary of "MAP.mg.sem" will produce parameter estimates,
> > goodness of fit indices, etc.), however, the bootSem function does not
> > run.
> > Any ideas on a workaround?
> >
> > MLM.MAP.Data$IAT.factor <- as.factor(IAT)
> > IAT.factor <- MLM.MAP.Data$IAT.factor
> > evaluative.MAP.data <- subset(data.frame(IAT.factor, exp.race,
> > meditation.experience, years.meditate, repeated.iat, repeated.ERN, age,
> > acceptance, awareness, FCz.GNG.150.incor, FCz.GNG.150.cor,
> > FCz.stereo.150.incor, FCz.stereo.150.cor, FCz.eval.150.incor,
> > FCz.eval.150.cor), IAT==2)
> > stereotype.MAP.data <- subset(data.frame(IAT.factor, exp.race,
> > meditation.experience, years.meditate, repeated.iat, repeated.ERN, age,
> > acceptance, awareness, FCz.GNG.150.incor, FCz.GNG.150.cor,
> > FCz.stereo.150.incor, FCz.stereo.150.cor, FCz.eval.150.incor,
> > FCz.eval.150.cor), IAT==1)
> >
> > MAP.stereotype.cov <- cov(na.omit(stereotype.MAP.data[,-1]))
> > MAP.evaluative.cov <- cov(na.omit(evaluative.MAP.data[,-1]))
> > MAP.cov.list <- list(stereotype=MAP.stereotype.cov,
> > evaluative=MAP.evaluative.cov)
> >
> > #### Specify your MSEM path model: Years Meditating, ERN, IAT####
> > MAP.msem.model <- specifyModel()
> > years.meditate -> repeated.ERN, path1
> > years.meditate -> repeated.iat, path2
> > repeated.ERN -> repeated.iat, path3
> > age -> repeated.iat, path4
> > years.meditate <-> years.meditate, var1
> > repeated.ERN <-> repeated.ERN, var2
> > age <-> age, var3
> > age <-> years.meditate, cov1
> > repeated.iat <-> repeated.iat, d1
> >
> > MAP.mg.mod <- multigroupModel(MAP.msem.model, groups=c("stereotype",
> > "evaluative"))
> >
> > MAP.mg.sem <- sem(MAP.mg.mod, MAP.cov.list,
> > c(nrow(stereotype.MAP.data),
> > nrow(evaluative.MAP.data)), group="IAT.factor")
> >
> > system.time(bootSem(MAP.mg.sem, R=100, MAP.cov.list))
> >
> > Error in bootSem.msem(MAP.mg.sem, MAP.cov.list, R = 100) :
> > the model object doesn't contain data matrices
> >
> > --
> > Chad M. Danyluck
> > PhD Candidate, Psychology
> > University of Toronto
> > Lab: http://embodiedsocialcognition.com
> >
> >
> > “There is nothing either good or bad but thinking makes it so.” -
> > William
> > Shakespeare
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
--
Chad M. Danyluck
PhD Candidate, Psychology
University of Toronto
Lab: http://embodiedsocialcognition.com
“There is nothing either good or bad but thinking makes it so.” - William
Shakespeare
[[alternative HTML version deleted]]
More information about the R-help
mailing list