tolerance <- tolerance <-
tolerance.long <- reshape(tolerance,
+ varying = list(c("tol11","tol12","tol13",
+ "tol14", "tol15")),
+ v.names = c("tol"), timevar = "time",
+ times = 11:15, direction = "long")
tolerance.aov2 <- aov(tol ~ factor(male) + factor(male):factor(id) +
factor(time) + factor(time):male, data = tolerance.long)
tolerance.sum <- summary(tolerance.aov2)
tolerance.sum
Df Sum Sq Mean Sq F value Pr(>F)
factor(male) 1 0.3599 0.3599 2.6077 0.111967
factor(time) 4 2.8326 0.7081 5.1309 0.001358 **
factor(male):factor(id) 14 8.2990 0.5928 4.2951 4.295e-05 ***
factor(time):male 4 0.1869 0.0467 0.3386 0.850786
Residuals 56 7.7289 0.1380
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tolerance.list <- tolerance.sum[[1]]
tolerance.mat <- as.matrix(tolerance.list[3])
tolerance.F.male <- tolerance.mat[1,1]/tolerance.mat[3,1]
tolerance.F.male
tolerance.df <- as.matrix(tolerance.list[1])
tolerance.p.male <- 1 -
pf(tolerance.F.male,tolerance.df[1,1],tolerance.df[3,1])
Message: 68
Date: Wed, 17 Jan 2007 05:45:01 -0500
From: Chuck Cleland <ccleland at optonline.net>
Subject: Re: [R] Repeated measures
To: Tom Backer Johnsen <backer at psych.uib.no>
Cc: r-help at stat.math.ethz.ch
Message-ID: <45ADFE2D.2060208 at optonline.net>
Content-Type: text/plain; charset=ISO-8859-1
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
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
and lme() in the nlme package.
tolerance <-
t",
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,