[R] Row-wise two sample T-test on subsets of a matrix

Petr Klasterecky klaster at karlin.mff.cuni.cz
Thu Mar 1 21:33:13 CET 2007


Ranjan Maitra napsal(a):
> Here's one suggestion: convert the matrix into a three-dimensional array and use apply on it. 

Converting to 3 dims should not be neccessary:
m <- matrix(rnorm(110),ncol=22)
t.list <- apply(m,1,function(x){t.test(x[1:11],x[12:22],paired=TRUE)})

However, I have no idea how much time it takes with almost 200.000 rows...
Petr

> 
> Ranjan
> 
> On Thu,  1 Mar 2007 11:51:29 -0600 (CST) Nameeta Lobo <nlobo at uchicago.edu> wrote:
> 
>> Hello all,
>>
>> I am trying to run a two sample t-test on a matrix which is a
>> 196002*22 matrix. I want to run the t-test, row-wise, with the
>> first 11 columns being a part of the first group and columns
>> 12-22 being a part of the second group. 
>>
>> I tried running something like (temp.matrix being my 196002*22
>> matrix)
>>
>> t.test(temp.matrix[,1:11],temp.matrix[,12:22],paired=TRUE)
>>
>> or somthing like
>>
>> as.numeric(t.test(temp.matrix[,1:11],temp.matrix[,12:22],paired=TRUE)[[1]])
>> so as to only capture the t-value alone and 
>>
>> and I get a result for the whole matrix instead of a row-wise
>> result. 
>>
>> I want to avoid using a "for" loop to increment the number of
>> rows as it would take a huge amount of time.
>>
>>
>> Any suggestions would be really appreciated.
>>
>> thanks
>> nameeta
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



More information about the R-help mailing list