[R] repeated measure one way anova

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Oct 28 08:58:00 CET 2008


Dieter Menne wrote:
> JohnLi <jli136 <at> site.uottawa.ca> writes:
>> I am a new comer for Statistics R. I am using R for one way repeated
>> measure anova, for example, on the following data consisting of three
>> groups.
>>
>>
>> c2	c3	c4
>> 85.83	75.86	84.19
>> 85.91	73.18	85.9
> 
> -- Arrange your data in the "long form". Do it by hand, or use function pack, or
> reshape, or package reshape.
> 
> (Assuming these are times. If these are categorical variables, better use
> strings as column descriptors)
> 
> 
> 
> subj time conc    (do not use t or c as variable name, these are 
>               "well-known functions" in R) 
> A     2    85.83
> A     3    75.86
> A     4    84.19
> B     2    85.91
> ....
> 
> Use package nlme, function lme. It might be a bit of an overkill for the simple
> case, but always worth the effort when things get more complex
> 
> libary(nlme)
> summary(lme(c~time, random=~1|subj,data=mydata)

There is also anova.mlm:

d <- read.table("clipboard", header=T)
Y <- as.matrix(d)
fit1 <- lm(Y~1)
fit0 <- lm(Y~0)
anova(fit0, fit1, X=~1, test="Spherical")
anova(fit0, fit1, X=~1, test="Wilks")

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list