[R] Repeated measures
Chuck Cleland
ccleland at optonline.net
Wed Jan 17 11:45:01 CET 2007
Tom Backer Johnsen wrote:
> I am having a hard time understanding how to perform a "repeated
> measures" type of ANOVA with R. When reading the document found here:
>
> http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_repms.html
>
> I find that there is a reference to a function make.rm () that is
> supposed to rearrange a "one row per person" type of frame to a "one
> row per observation" type of frame. But that function does not seem
> to be there. Nor does the help.search suggest anything. Is that
> function buried in some package?
I'm not able to find that function. Perhaps that document is out of date.
> Is there some simple documentation that might be useful somewhere?
> Starting with a really simple problem (one group, two observations)?
Here is an example showing the use of reshape() and analysis via aov()
and lme() in the nlme package.
tolerance <-
read.table("http://www.ats.ucla.edu/stat/Splus/examples/alda/tolerance1.txt",
sep=",", header=TRUE)
tolerance.long <- reshape(tolerance,
varying = list(c("tol11","tol12","tol13",
"tol14", "tol15")),
v.names = c("tol"), timevar = "time",
times = 11:15, direction = "long")
tolerance.aov <- aov(tol ~ as.factor(time) * male + Error(id),
data = tolerance.long)
summary(tolerance.aov)
Error: id
Df Sum Sq Mean Sq
male 1 0.085168 0.085168
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
as.factor(time) 4 2.8326 0.7081 3.0538 0.02236 *
male 1 0.3024 0.3024 1.3039 0.25745
as.factor(time):male 4 0.1869 0.0467 0.2015 0.93670
Residuals 69 16.0002 0.2319
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(nlme)
tolerance.lme <- lme(tol ~ as.factor(time) * male, random = ~ 1 | id,
data = tolerance.long)
anova(tolerance.lme)
numDF denDF F-value p-value
(Intercept) 1 56 353.9049 <.0001
as.factor(time) 4 56 5.1309 0.0014
male 1 14 0.6071 0.4488
as.factor(time):male 4 56 0.3386 0.8508
RSiteSearch("repeated measures") points to other examples, functions,
and documentation.
> Tom
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
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