Skip to content

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

2 messages · J., Charles C. Berry

J.
#
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.
#
On Mon, 9 Nov 2009, J. wrote:

            
Vectorize the whole thing:


adf <- as.data.frame( aperm( A, c(4,1,2,3)))
tA2 <- array( mean(adf) / sd(adf) * sqrt(8), c(128,128,1))


HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901