[R] Plot interaction in multilevel model

dadrivr dadrivr at gmail.com
Sat Mar 6 03:39:42 CET 2010


I am trying to plot an interaction in a multilevel model.  Here is some
sample data.  In the following example, it is longitudinal (i.e., repeated
measures), so the outcome, score (at each of the three time points), is
nested within the individual.  I am interested in the interaction between
gender and happiness predicting score.

id <- c(1,1,1,2,2,2,3,3,3)
age <- c(10,15,20,10,15,20,10,15,20)
gender <- c(1,1,1,0,0,0,1,1,1)
happiness <- c(50,30,25,70,65,80,70,40,60)
score <- c(180,140,110,240,220,280,150,140,130)
mydata <- data.frame(id,age,gender,happiness,score) 

I am looking to create two plots:

1. A plot with score on the y-axis, happiness on the x-axis, gender as the
moderating variable, and a linear best-fit line for each level of gender
(male & female).  Here is my attempt, but I don't know how to make it into
linear best-fit lines:
with(mydata,interaction.plot(happiness,gender,score))

2. A plot with score on the y-axis, age on the x-axis, and 4 different best
fit lines representing the following levels of gender and happiness (male hi
happy, male lo happy, female hi happy, female lo happy).  Here is my
attempt, but I don't know how to create the 4 different best-fit lines
representing the 4 different interaction levels:
with(mydata,interaction.plot(age,gender,score))

Any ideas?  Any help would be greatly appreciated with these two plots. 
Thanks so much!
-- 
View this message in context: http://n4.nabble.com/Plot-interaction-in-multilevel-model-tp1580370p1580370.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list