[R] ANOVA vs REML approach to variance component estimation
Adaikalavan Ramasamy
ramasamy at cancer.org.uk
Fri Jun 10 19:35:02 CEST 2005
Can anyone verify my calculations below or explain why they are wrong ?
I have several animals that were measured thrice. The only blocking
variable is the animal itself. I am interested in calculating the
between and within object variations in R. An artificial example :
y <- c( 2.2, -1.4, -0.5, # animal 1
-0.3 -2.1 1.5, # animal 2
1.3 -0.3 0.5, # animal 3
-1.4 -0.2 1.8) # animal 4
ID <- factor( rep(1:4, each=3) )
1) Using the ANOVA method
summary(aov( y ~ ID ))
Df Sum Sq Mean Sq F value Pr(>F)
ID 3 0.900 0.300 0.1207 0.9453
Residuals 8 19.880 2.485
=> within animal variation = 2.485
=> between animal variation = (0.300 - 2.485)/3 = -0.7283
I am aware that ANOVA can give negative estimates for variances. Is this
such a case or have I coded wrongly ?
2) Using the REML approach
library(nlme)
lme( y ~ 1, rand = ~ 1 | ID)
....
Random effects:
Formula: ~1 | ID
(Intercept) Residual
StdDev: 0.01629769 1.374438
=> within animal variation = 1.374438^2 = 1.88908
=> between animal variation = 0.01629769^2 = 0.0002656147
Is this the correct way of coding for this problem ? I do not have
access to a copy of Pinheiro & Bates at the moment.
Thank you very much in advance.
Regards, Adai
More information about the R-help
mailing list