0

So I've looked at a number of similarly themed posts but none of them seem to be exactly what I need, or I simply don't really understand the solutions they offered... So here it goes...

I ran a mixed-effects model with lme4 to look at some chimpanzee data. I have two factors (aggression rate; copulation rate) which affect my dependent (feeding time).

I would like to produce two scatter plots which show the relationship between each of the predictors and the outcome variable but I would like to draw a line, which is derived from the model estimates (and not an abline of the (lm(y ~ x)) type, which only gives a simple regression line, not one based on the full LMM).

I have a sense that this is only possible with ggplot2 but I have not been able to actually figure out how to do this. Having spent most of the day looking through books and forums, I was hoping this is something that may have a fairly straight-forward answer, if one knows what they are doing.

Thanks for any tips in advance!

Alex

1 Answers1

1

To begin with I had the following model:

M3reml
Linear mixed model fit by REML ['lmerMod']
Formula: z.feeding_time ~ z.copul_rate + z.agro_given + z.agro_recd + (1 | Male) + ac_term
   Data: N85

where the variables are the z-transformed values of: male chimpanzee feeding time (z.feeding_time); daily copulation rates with females (acts/hr; z.copul_rate); daily rate of aggression given (z.agro_given); and daily rate of aggression received (z.agro_recd). Random effect – male ID for the 12 males of my study; and a temporal autocorellation term (ac_term).

I wanted produce a regression line based on the model estimates for male feeding time.

Getting the estimates:

p1<-predict(M3reml)

Plotting the estimates against male rates of aggression (z-transformed values):

plot(p1~z.agro_given, data=N85)

adding a regression line:

abline(lm(p1~z.agro_given, data=N85))

I would post an image of the plot here but apparently I am not allowed to yet.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294