[R] multiple tests: t-statistic for vectors in 4-dimensional array

J. jokesrquestions at gmail.com
Mon Nov 9 16:06:29 CET 2009


Hi everyone,

I created a four dimensional vector (dim (128,128,1,8)).  This third 
dimension is necessary for another function somewhere.  Now I'd like to 
perform a t-test on every vector of length 8 in my array on the fourth 
dimension.
I'd like to obtain a new array of three dimensions with dimensions 
128x128x1 with all these test statistics.

I tried this with a double loop:

A <- array(rep(seq(-1:2),128*128*8),dim=c(128,128,1,8)) #in simulations 
I fill the array with random variables
tA <- array(rep(NA,128*128),dim=c(128,128,1))

for (i in 1:128){
for (j in 1:128){
print(c(i,j))
tA[i,j,1] <- t.test(A[i,j,1,],alternative="two.sided",mu=0)$statistic
}}

This works, but it takes way to much time, since I'd like to run this 
about 500 times.

I read something about the apply function, but there I don't know how to 
specify the outcome values ($statistic), plus I have some difficulties 
with the specification of my vectors...
This doesn't work:
tA <- apply(smoothA,4,t.test$statistic)

"Error in t.test$statistic : object of type 'closure' is not subsettable"

I sought in the package multtest, but can't find any helpful function.

Thanks,

J.




More information about the R-help mailing list