Thanks again John. I think the problem is now resolved. I changed the information that I passed through the sem() as follows:
MAP.mg.sem <- sem(MAP.mg.mod, data=list(stereotype=stereotype.MAP.data, evaluative=evaluative.MAP.data), group="IAT.factor") Then, from ?bootSem "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." >From this I realized that I don't need to pass anything about the data or the Cov into bootSem() and so booted.sem <- bootSem(MAP.mg.sem, R=100) And I get the anticipated return. Interestingly, when I tried to pass the Cov and data into the bootSem() like this: booted.sem <- bootSem(MAP.mg.sem, R=100, Cov=cov, data=list(stereotype=stereotype.MAP.data, evaluative=evaluative.MAP.data)) I had a failure to converge. Kind regards! Chad On Tue, Sep 2, 2014 at 4:03 PM, John Fox <j...@mcmaster.ca> wrote: > Dear Chad, > > > -----Original Message----- > > From: Chad Danyluck [mailto:c.danyl...@gmail.com] > > Sent: Tuesday, September 02, 2014 3:29 PM > > To: John Fox > > Cc: r-help@r-project.org > > Subject: Re: [R] Problems bootstrapping multigroup SEM > > > > 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? > > I'm sorry but I don't follow this: c(nrow(stereotype.MAP.data), > nrow(evaluative.MAP.data)) are simply the numbers of observations in the > data sets, not the data sets themselves. From what you've said, the data > sets are stereotype.MAP.data and evaluative.MAP.data. You can use the data > and formula arguments to sem(). You need the explicit formula argument > because you're apparently omitting one of the variables in each data set; > alternatively, you can directly remove the unused variable from each data > set, as you've done above. And you need not filter out the missing data > (though it doesn't hurt to do so), since the default na.action is na.omit > (as is shown in ?sem). > > From ?sem: > > "data: As a generally preferable alternative to specifying S and N, the > user may supply a data frame containing the data to which the model is to > be fit. In a multigroup model, the data argument may be a list of data > frames or a single data frame; in the later event, the factor given as the > group argument is used to split the data into groups." > > and > > "formula: a one-sided formula, to be applied to data to generate the > variables for which covariances or raw moments are computed. The default > formula is ~., i.e., all of the variables in the data, including an implied > intercept; if a covariance matrix is to be computed, the constant is > suppressed. In a multigroup model, alternatively a list one one-sided > formulas as be given, to be applied individually to the groups." > > The multigroup example given in ?sem for the HS.data uses a single data > frame, which is then classified by the factor Gender. In your case, you'd > specify a list of two data frames; if the same variables are to be used in > each, then you need give only one formula rather than a list of two, though > the latter would also work. > > Best, > John > > > > > 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 <j...@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-boun...@r-project.org [mailto:r-help-bounces@r- > > > project.org] On Behalf Of Chad Danyluck > > > Sent: Wednesday, August 27, 2014 12:22 PM > > > To: r-help@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@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 > > <http://embodiedsocialcognition.com/> > > > > > > > > > > “There is nothing either good or bad but thinking makes it so.” - > > William Shakespeare > > > -- 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@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.