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

4
  • 5
    You'll get more help if you make your question reproducible Commented Mar 31, 2014 at 21:06
  • 1
    ?predict.merMod might help you. Commented Mar 31, 2014 at 21:44
  • please write up an answer to your own question and post it (as soon as you're allowed too -- there may be a minimum time limit) Commented Apr 1, 2014 at 18:17
  • Does that look right (my answer below)? Commented Apr 1, 2014 at 18:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Not sure why the formatting of the text looks so atrocious though... Have not done this before, clearly.
Ah. thanks for editing this... I will try to figure out how this works next time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.