Skip to content
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

Open
fbonier opened this issue Apr 13, 2021 · 6 comments
Open

ggeffects error for MCMCglmm #206

fbonier opened this issue Apr 13, 2021 · 6 comments
Labels
3 investigators ❔❓ bug 🐛 Something isn't working help us 👀 Help is needed to implement something

Comments

@fbonier
Copy link

fbonier commented Apr 13, 2021

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!

@strengejacke
Copy link
Owner

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")

@strengejacke strengejacke added waiting for response 💌 Response from users awaited bug 🐛 Something isn't working labels Apr 13, 2021
@fbonier
Copy link
Author

fbonier commented Apr 14, 2021

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.

@strengejacke
Copy link
Owner

Could you provide a small, reproducible example? I guess the issue arises when calculating the standard errors for predictions.

strengejacke added a commit that referenced this issue Apr 26, 2021
@strengejacke
Copy link
Owner

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")

@fbonier
Copy link
Author

fbonier commented Apr 27, 2021

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.

@strengejacke
Copy link
Owner

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)

@strengejacke strengejacke added 3 investigators ❔❓ help us 👀 Help is needed to implement something and removed waiting for response 💌 Response from users awaited labels May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 investigators ❔❓ bug 🐛 Something isn't working help us 👀 Help is needed to implement something
Projects
None yet
Development

No branches or pull requests

2 participants