-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggeffects error for MCMCglmm #206
Comments
I have recently fixed a similar issue, maybe your issue is resolved as well. Could you please try to update ggeffects from GitHub? remotes::install_github("strengejacke/ggeffects") |
Thanks so much for the suggestion - I just tried updating ggeffects with the GitHub version, but I am still getting the same error. Too bad, because the plot I've made from the lme is perfect! I think I can manually generate a similar plot for the MCMCglmm - just not as easily as with ggeffects. |
Could you provide a small, reproducible example? I guess the issue arises when calculating the standard errors for predictions. |
I possibly found the bug and hopefully fixed it. Could you please try to install ggeffects from GitHub again, and retry? remotes::install_github("strengejacke/ggeffects") |
Well, I now get a different error - so maybe that's progress!? Now it's: "Error in predict.MCMCglmm(model, newdata = new_grid, type = "response", : model for newdata has fixed effects absent from the original model" Thanks so much for continuing to try to work with this! I'll simplify my code and send it to you with the data, so you can reproduce the error I'm getting. |
This is the code that produces the error (just a reminder for myself): library(ggeffects)
grid <- data_grid(m, c("zSpp.Mean.Urb.Occur [all]", "Migratory.Resident", "Breeding.Non"))
grid$SEX <- c("FEMALE", "MALE")
all(all.vars(formula(m)) %in% colnames(grid))
predict(m, newdata = grid) |
I am loving ggeffects for plotting results of lme's, but just tried to use it to illustrate a 3-way interaction from an MCMCglmm. It works great for the same LME, with the same data, just not controlling for phylogeny, but in the MCMCglmm, when I try to run this line of code:
SIplot.predict.phy<-ggpredict(SI.bestmodel.phy, c("zSpp.Mean.Urb.Occur [all]", "Migratory.Resident", "Breeding.Non"))
I get this error:
Error in
contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) :contrasts can be applied only to factors with 2 or more levels
The full model that I am trying to plot is: SI.bestmodel.phy <- MCMCglmm(LnMeanSIcort ~ Breeding.Non + Migratory.Resident + SEX + zAbsLat + zSpp.Mean.Urb.Occur + Breeding.Non:Migratory.Resident + Breeding.Non:SEX + Breeding.Non:zAbsLat + Breeding.Non:zSpp.Mean.Urb.Occur + Migratory.Resident:SEX + Migratory.Resident:zAbsLat + Migratory.Resident:zSpp.Mean.Urb.Occur + zAbsLat:zSpp.Mean.Urb.Occur + Breeding.Non:Migratory.Resident:zAbsLat + Breeding.Non:Migratory.Resident:zSpp.Mean.Urb.Occur, random =~ animal, pedigree = SIcort.tree, family="gaussian", data = allSIdata_2, nitt=100000, burnin=10000, thin=1, prior=prior.model1)
I have verified that all of the categorical predictors, including the phylogeny, are being treated as factors, and all of them do indeed have 2 or more levels.
I can provide more details if it would help. Thanks!
The text was updated successfully, but these errors were encountered: