[R-sig-ME] Plotting MCMCglmm model predict line
Tara Cox [RPG]
b@t|c @end|ng |rom |eed@@@c@uk
Thu Nov 10 12:32:36 CET 2022
Dear list,
I was hoping to get some help with a query regarding the predict.MCMCglmm() function.
I have run a univariate MCMCglmm with behaviour score as the response variable (Poisson distribution) and five fixed effects (age, age squared, sex, test number and room colour). I would like to visualize a significant quadratic age effect by plotting the model predict line and corresponding 95% credible intervals over the raw values.
I have tried to do this using predict.MCMCglmm and ggplot2, but this produces a 'jaggered' output (plot attached). Therefore I was hoping someone could help shed some light on what I might be doing wrong.
Below are my model specification and the code for plotting the model predict line:
model<- MCMCglmm(BehaviourScore~
Age_years_integer+
Age_years2_integer+
Sex +
TestNumber +
RoomColour,
random=~BirdID+ObserverID,
nitt=1260000,
burnin=60000,
thin=300,
verbose=FALSE,
pr=TRUE,
family="poisson",
data=Behaviour_data)
mpred <- predict(model, interval="confidence", marginal=~ BirdID + ObserverID)
dataf <- data.frame(Behaviour_data, mpred)
ggplot(dataf , aes(x=Age_years_integer, y=BehaviourScore))+
geom_point(colour="grey6", alpha=0.30) +
xlab("Age (years)") + ylab("Behaviour score (integer)") + theme_classic() +
geom_line(data=dataf, aes(x=Age_years_integer, y=fit)) +
geom_ribbon(data=dataf, aes(x=as.numeric(Age_years_integer), y=fit,ymin=lwr, ymax=upr),fill="red",alpha=0.3)
Apologies if this is a straightforward question, I have tried googling the issue but have had no luck.
Many thanks,
Tara
Tara Cox
Pronouns: she, her
PhD researcher
Dugdale group, School of Biology
Faculty of Biological Sciences
University of Leeds
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AgeEffect.png
Type: image/png
Size: 7050 bytes
Desc: AgeEffect.png
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20221110/7d782979/attachment.png>
More information about the R-sig-mixed-models
mailing list