[R] sphericity calculation (more formulas?)
John Christie
jc at or.psychology.dal.ca
Sat Dec 13 19:28:11 CET 2003
I believe that the following function is a good function for eyeballing
sphericity. But, I can't find functions for tests anywhere (g-g or
h-f). Anyone who wants to can feel free to use it.
It is bad that R does not provide any tests for sphericity AND cannot
do a MANOVA on repeated measures (although lme is an alternative add on
package). One of these solutions must be provided in the base
configuration. My understanding is that the R community is opposed to
F corrections and I can see the argument. But, not providing any way
of looking at sphericity at all in order to see if you need to go
through the extra steps of adding a separate package and learning a
somewhat more complicated command set is just wrong.
Also, Loftus & Masson have long been arguing that one use the MSE error
term from repeated measures in order to generate confidence intervals
for the means. But, without a test of sphericity one cannot check to
see if this is OK to do. It is not entirely unreasonable to want to
provide some variance for graphical presentation even if your analyses
use the "correct" lme. You can explain in the text. But, the lme
cannot provide a variance measure since it just uses likelihood ratios.
Oh, and if this little sphericity function is wrong please correct.
# this returns an array with the variances between each condition. This
# can be calculated using a covariance matrix and that might technically
# be faster. But this method is more transparent with respect to
defining
# sphericity.
jcsphericity <- function(x){
# x is a matrix that consists of columns containing each condition and
# rows for each s. e.g. matrix(s$x,ncol=3) where s$x is a long
formatted
# dv with 3 cond and with cond moving faster than s if all the values
returned
# are roughly equal sphericity is OK (never happens :))
n<- length(x[1,])
t<-array()
l<-array()
k<-0
for (i in 1:(n-1)){
for (j in (i+1):n){
k<-k+1
t[k]<- var(x[,i] - x[,j])
l[k]<- paste(i,j, sep=",")
}
}
names(t)<-l
t
}
More information about the R-help
mailing list