Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread jim holtman
Your time is being taken up in cor.test because you are calling it 100,000 times. So grin and bear it with the amount of work you are asking it to do. Here I am only calling it 100 time: m1 - matrix(rnorm(1), ncol=100) m2 - matrix(rnorm(1), ncol=100) Rprof('/tempxx.txt')

Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread David Winsemius
He might try rcorr from Hmisc instead. Using your test suite, it gives about a 20% improvement on my MacPro: m1 - matrix(rnorm(1), ncol=100) m2 - matrix(rnorm(1), ncol=100) Rprof('/tempxx.txt') system.time(cor.pvalues - apply(m1, 1, function(x) { apply(m2, 1, function(y) {

Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread Jorge Ivan Velez
Hi Daren, Here is another aproach a little bit faster taking into account that I'm using your original matrices. My session info is at the end. I'm using a 2.4 GHz Core 2-Duo processor and 3 GB of RAM. # Data set.seed(123) m1 - matrix(rnorm(10), ncol=100) m2 - matrix(rnorm(10),

Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread hadley wickham
On Wed, Nov 26, 2008 at 8:14 AM, jim holtman [EMAIL PROTECTED] wrote: Your time is being taken up in cor.test because you are calling it 100,000 times. So grin and bear it with the amount of work you are asking it to do. Here I am only calling it 100 time: m1 - matrix(rnorm(1),

Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread Daren Tan
Out of desperation, I made the following function which hadley beats me to it :P. Thanks everyone for the great help. cor.p.values - function(r, n) { df - n - 2 STATISTIC - c(sqrt(df) * r / sqrt(1 - r^2)) p - pt(STATISTIC, df) return(2 * pmin(p, 1 - p)) } Date: Wed, 26 Nov 2008

Re: [R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-26 Thread Thomas Lumley
You can do much better by doing the correlations as a matrix operation: system.time({ + m1-scale(m1) + m2-scale(m2) + r-crossprod(m1,m2)/100 + df-100 + tstat-sqrt(df)*r/sqrt(1-r^2) + p-pt(tstat,df) + }) user system elapsed 0.025 0.004 0.028

[R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

2008-11-25 Thread Daren Tan
My two matrices are roughly the sizes of m1 and m2. I tried using two apply and cor.test to compute the correlation p.values. More than an hour, and the codes are still running. Please help to make it more efficient. m1 - matrix(rnorm(10), ncol=100) m2 - matrix(rnorm(1000), ncol=100)