Skip to content

Repeated measures

2 messages · Richard Plant, Chuck Cleland

#
In the two solutions for the repeated measures problem given in the
original reply below, the F and p values given by aov() with the error
strata defined by Error() are different from those given by lme().
However, when one does the problem "by hand" using the standard split
plot model, the results agree with those of nlme(). The difference
between the two aov() solutions is in the partitioning of sums of
squares. Is there a ready explanation for this discrepancy?

Thanks,
Richard Plant
+
read.table("http://www.ats.ucla.edu/stat/Splus/examples/alda/tolerance1.
txt",
+             sep=",", header=TRUE)
+                           varying = list(c("tol11","tol12","tol13",
+                                            "tol14", "tol15")),
+                           v.names = c("tol"), timevar = "time",
+                           times = 11:15, direction = "long")
factor(time) + factor(time):male, data = tolerance.long)
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
[1] 0.607137
pf(tolerance.F.male,tolerance.df[1,1],tolerance.df[3,1])
[1] 0.4488394
here:
aov()
read.table("http://www.ats.ucla.edu/stat/Splus/examples/alda/tolerance1.
tx
functions,
#
Richard Plant wrote:
The discrepancy in this case is due to a mistake on my part.  The id
variable should be a factor.

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 ~ factor(time) * male + Error(factor(id)),
                     data = tolerance.long)

summary(tolerance.aov)

Error: factor(id)
          Df Sum Sq Mean Sq F value Pr(>F)
male       1 0.3599  0.3599  0.6071 0.4488
Residuals 14 8.2990  0.5928

Error: Within
                  Df Sum Sq Mean Sq F value   Pr(>F)
factor(time)       4 2.8326  0.7081  5.1309 0.001358 **
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

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

  Could anyone point me to an example where the variable specified
inside of Error() is not a factor?