Problem with "newdata" argument in R predict function w/ MCMC Model

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Problem with "newdata" argument in R predict function w/ MCMC Model


I am having issues getting the "newdata" argument in my predict function to work. In particular, when I run the code below (3rd line), I get the error: Error in eval(expr, envir, enclos) : object 'Risk' not found. I'm assuming that I either have a) formatting issues in the "newdata" dataframe or b) I am somehow entering the data incorrectly into the MCMCglmm model.

I am using a Markov-chain Monte Carlo glmm to model my data (this is in the "MCMCglmm" package). Please note that for simplicity in the sake of this question, there are certain things I took out of the predict function, so the code below will not do what is statistically responsible (note I also get the same error when I DO add statistically responsible arguments).


ptsdMCMC.mod <- MCMCglmm(Risk ~ poly(Trial,2) * Group * Stimulus, family = "ordinal", data = ptsd.df, nitt = 100000)

newdata <- expand.grid(Trial=1:10, Stimulus=levels(ptsd.df$Stimulus), Group=levels(ptsd.df$Group))

ptsd.predict <- predict(ptsdMCMC.mod, newdata = newdata)

"Risk" is ordinal - with values of 0, 1, & 2

"Group" is nominal - 3 different groups

"Trial" is ordinal - there are 10 trials

"Stimulus" is ordinal - there are 6 different stimuli in increasing size

Each participant has a value for each Trial*Stimulus combo (i.e. there are 60 total observations per participant).

Do you see anything wrong with the formatting of my "newdata" data frame, where it would not work within the context of the predict function and produce this error? If not, I believe that narrows it down to problems with the MCMCglmm model estimation. Do also note that if I take out the "newdata" argument, the predict function works. However, it estimates data points based on the original dataset "ptsd.df", which includes estimation based on subject ID, which I don't want (also, it's not even part of the original model).