[R] Change properties of line summary in interaction.plot

David Winsemius dwinsemius at comcast.net
Thu Sep 8 02:04:42 CEST 2011


On Sep 7, 2011, at 6:31 PM, dadrivr wrote:

>
> Here's an example:
>> id <-  
>> c(17,17,17,18,18,18,19,19,19,20,20,20,21,21,21,22,22,22,23,23,23,24,
>>        24,24,25,25,25,26,26,26)
>> age <- rep(c(30,36,42),10)
>> outcome <-
>> c(12,17,10,5,5,2,NA,NA,NA,8,6,5,11,13,10,15,11,15,13,NA,9,0,0,0,20,
>>             14,16,1,2,2)
>> mydata <- as.data.frame(cbind(id,age,outcome))
>> interaction.plot(mydata$age, mydata$id, mydata$outcome, fun = mean,  
>> legend
>> = FALSE, lty = 1, xtick = TRUE, type = "l")
>>
>> How can I make the 'mean' summary line red and thicker?
>
>
> David Winsemius wrote:
>>
>> On Sep 7, 2011, at 4:49 PM, dadrivr wrote:
>>
>>>
>>> David Winsemius wrote:
>>>> What "mean summary line"? I count 8 lines and that matches the  
>>>> number
>>>> if id's with complete data.
>>>
>>> Yea, I don't know why there is no mean summary line showing up.  I
>>> requested
>>> it in the interaction.plot statement (fun = mean), and I don't get  
>>> any
>>> errors.
>>
>> You didn't get any errors and you _did_ get the means. It's just that
>> you only gave it a dataset that had only one value per category. The
>> mean is defined for a single element vector although the sd and var
>> are not. Look more closely at the example on the help page and you
>> will see that it has more than one value per category defined by the
>> two interaction variables
>
> Okay, I checked the example, and I see what you mean.  Is there a  
> way to
> compute an average trajectory (i.e., a line that represents the  
> averages of
> all the other lines) and make that line red?  Obviously, I'm fairly  
> new to
> this in general, so any guidance would be helpful.

 > mydat.mdl <- lm(outcome ~ age, data=mydata)
 > with( mydata, plot(age, outcome))
 > abline(coef(mydat.mdl), col="red")

-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list