[R] resampling for correlation and testing
Benton, Paul
hpaul.benton08 at imperial.ac.uk
Wed Mar 28 23:53:17 CEST 2012
Hello all R-er,
I'm trying to run a resampling method on some data. The current method I have takes 2+ days or a lot of memory . I was wondering if anyone has a better suggestion.
Currently I take a matrix and get the correlation matrix from it. This will be called rho.A. Each element in this will be tested against the distribution from the resampled correlation B matrix.
Some example code:
A<-matrix(rnorm(100), ncol=10)
B<-matrix(rnorm(100), ncol=10)
rho.A<-cor(A)
{
idx<-sample(1:10, 10)
idx
# [1] 8 4 5 7 1 9 2 10 6 3
rho.B<-cor(B[,idx])
} ## repeat this x time (currently 500)
## in essence we then have the following :
rho.arrayB<-array(runif((10*10)*500), dim=c(10,10,500))
## Then test if rho.A[1,1] come from the distribution of rho.B[1,1]
pvalueMat[1,1]<-wilcox.test(rho.array[1,1,] , rho.A[1,1])$p.value
However, my array size would be 2300 x 2300 x 500 which R won't let me even make as an empty structure. Any suggestion are more than welcomed !!
Cheers,
Paul
More information about the R-help
mailing list