[R] s.e. on interaction plots

Chuck Cleland ccleland at optonline.net
Fri Nov 17 11:21:38 CET 2006


Murray Pung wrote:
> Is it possible to add standard error bars to the means on interaction plots?

  Not with interaction.plot(), as far as I know.  You might consider the
effects package by John Fox.  For example:

with(ToothGrowth, interaction.plot(dose, supp, len))

ToothGrowth$dose <- as.factor(ToothGrowth$dose)

TG.lm <- lm(len ~ supp * dose, data = ToothGrowth)

library(effects) # loads lattice and grid packages

plot(effect("supp:dose", TG.lm))

  You also could construct your own plot using the standard errors
produced by effect():

sum.df <- data.frame(len = effect("supp:dose", TG.lm)$fit,
                     se = effect("supp:dose", TG.lm)$se,
                     supp = rep(c("OJ", "VC"), 3),
                     dose = rep(c(.5,1,2), each = 2))

library(Hmisc)

xYplot(Cbind(len, len - se, len + se) ~ dose | supp, data=sum.df,
       type="b", ylim=c(0,30))

xYplot(Cbind(len, len - se, len + se) ~ dose, groups=supp, data=sum.df,
       type="b", ylim=c(0,30))

> Thanks
> Murray

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list