[R-sig-ME] Plotting MCMCglmm model predict line

Walid Mawass w@||dm@w@@@10 @end|ng |rom gm@||@com
Thu Nov 10 17:19:42 CET 2022


Hi Tara,

I see two possible things that might be giving you this plot. First, when
you are using geom_line, to draw a regression line, the argument
stat="smooth" is required. If it is not included, I think the function just
connects the predicted points with lines.
Second, you mentioned you want to plot the quadratic effect, to do that
with geom_line, you should add the formula. For quadratic: formula = y ~
x + I(x^2).

Another suggestion would be to limit your yaxis using ylim(min, max) since
it is flattening the data visually.

Hope this helps.
-- 
Walid Mawass
Ph.D. in Evolutionary Biology - UQTR
Postdoctoral Research Associate
Masel Lab - University of Arizona


On Thu, Nov 10, 2022 at 4:32 AM Tara Cox [RPG] <bstlc using leeds.ac.uk> wrote:

> 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
>
>
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list