[R] box correction or Huynh-Feldt epsilon
John Christie
jc at or.psychology.dal.ca
Tue Dec 16 16:04:07 CET 2003
Following up the several unanswered requests for a sphericity or
circularity test in the archives, those who wish to test should feel
free to use the following function. If anyone notices errors please
correct. The returned value is an epsilon one can use to correct
degrees of freedom. It is less conservative than the
Greenhouse-Geisser I believe.
# This returns the Huynh-Feldt or "Box Correction" for degrees of
freedom
hf <- function(m){
# m is a matrix with subjects as rows and conditions as columns
# note that checking for worst case scenarios F correction first might
# be a good idea using J/(J-1) as the df correction factor
n<- length(m[,1])
J<-length(m[1,])
X<-cov(m)*(n-1)
r<- length(X[,1])
D<-0
for (i in 1: r) D<- D+ X[i,i]
D<-D/r
SPm<- mean(X)
SPm2<- sum(X^2)
SSrm<-0
for (i in 1: r) SSrm<- SSrm + mean(X[i,])^2
epsilon<- (J^2*(D-SPm)^2) / ((J-1) * (SPm2 - 2*J*SSrm + J^2*SPm^2))
epsilon
}
More information about the R-help
mailing list