[R] H-F corr.: covariance matrix for interaction effect
Bela Bauer
bela_b at gmx.net
Wed Feb 23 12:08:53 CET 2005
Hi,
I'm still not quite there with my H-F (G-G) correction code. I have it
working for the main effects, but I just can't figure out how to do it
for the effect interactions. The thing I really don't know (and can't
find anything about) is how to calculate the covariance matrix for the
interaction between the two (or even n) main factors.
I've looked through some books here and I've tried everything that came
to my mind, but I can't seem to be able to figure out an algorithm that
does it for me.
Could anyone give me a hint about how I could do this?
(I'll append my code at the end, in case that helps in any way...)
Thanks
Bela
# parameters for this function are:
# S - variance matrix (created by var() )
# k - number of factor levels (i.e. dim of S)
# n - number of measurements (i.e. number of rows in original matrix)
epsi.GG.HF <- function (S,k,n) {
D <- (k^2 * (mean(S) - mean(diag(S)))^2)
N1 <- sum(S^2)
N2 <- 2 * k * sum(apply(S, 1, mean)^2)
N3 <- k^2 * mean(S)^2
epsiGG <- D / ((k - 1) * (N1 - N2 + N3))
epsiHF <- (n * (k-1) * epsiGG - 2) / ((k-1) * ((n-1) - (k-1)*epsiGG))
c(epsiGG,epsiHF)
}
# three factors, facROI,facCond,facSubj
# facROI,facCond are main effects, facSubj is "repeatedness"
# G-G and H-F corrections for a main effect
# we do the gghf stuff for the ROI, which means ROIs in columns,
# subjects in rows
mtx <- NULL
for (iROI in 1:length(unique( facROI ))) {
for (iSubj in 1:length(unique( facSubj ))) {
mtx <- c(mtx,
mean(vecData[facROI==unique(facROI)[iROI] &
facSubj==unique(facSubj)[iSubj]])
)
}
}
mtx <- matrix(mtx,ncol=length(unique( facROI )),byrow=F)
GgHfROI <- epsi.GG.HF(var(mtx),length(mtx[1,]),length(mtx[,1]))
print(GgHfROI)
# now for the facROI:facCond interaction...how to go about this?
More information about the R-help
mailing list