[R] Performing t tests between matrices

John Smith nn532 at nyu.edu
Thu Apr 19 20:12:53 CEST 2012


I need to perform 10000 T tests 

#I have two populations with different means
Popc1<-rnorm(100000,10,2)
Popc2<-rnorm(100000,8,2)

#I created two sets of samples - each set has 10000 samples, and I made a
matrix of 20 rows and 10000 columns to fit the data 

sampc1<-matrix(,20,10000) 
for(j in 1:10000){sampc1[1:20,j]<-sample(Popc1,20)}
sampc2<-matrix(,20,10000) 
for(j in 1:10000){sampc2[1:20,j]<-sample(Popc2,20)}

#I wrote a blank matrix with 1 row and 10000 columns. I am planning to fill
this matrix with the t values that i calculate for each pair of samples
t<-matrix(,1,10000)

#What i need to do is to calculate the t value for each pair of samples: So
if i were to do it manually, for the first sample in each set, I would do
something like: 

t.test(sampc1[,1],sampc2[,1])
#And i would continue doing this all the way until the 10000th pair of
samples 
so t.test(sampc1[,2],sampc2[,2])
    t.test(sampc1[,3],sampc2[,3]) and so on 

#But i need to do this for all 10000 pairs of samples: 
#I tried to write a loop

for(j in 1:10000) {t[,1:10000]<-t.test(sampc1[, j],sampc2[, j])$statistic}

#but this fills each column in the matrix with the same exact t value.  

#Can someone tell me how to write the code to perform each pair of t tests?
I think i am missing something in my loop

Thanks


--
View this message in context: http://r.789695.n4.nabble.com/Performing-t-tests-between-matrices-tp4571706p4571706.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list