Reg : using two different matrix : how to do t.test

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Reg : using two different matrix : how to do t.test

pinal
I have two matrix with same dimensions. I want to do t.test using each column from 2 different matrix.  
Row n Column names in both matrix are same.
 
e.g.  
Matrix1      
id VC1 VC2 VC3      
R 1 2 3    
R1 4 5 6    
R3 7 8 9  
 
 
Matrix2    
id VC1 VC2 VC3
R 10 11 12
R1 13 14 15
R3 16 17 18
 
want to do t.test using each column (with same name ) using Matrix1 and Matrix2
 
for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
 
What is the best way to do it. I have dataset with 4000 columns for each matrix with same row and column names.
 
Thanks a lot.
       
---------------------------------
Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Odp: Reg : using two different matrix : how to do t.test

PIKAL Petr
Hi

[hidden email] napsal dne 19.11.2007 09:32:25:

> I have two matrix with same dimensions. I want to do t.test using each
column

> from 2 different matrix.
> Row n Column names in both matrix are same.
>
> e.g.
> Matrix1
> id VC1 VC2 VC3
> R 1 2 3
> R1 4 5 6
> R3 7 8 9
>
>
> Matrix2
> id VC1 VC2 VC3
> R 10 11 12
> R1 13 14 15
> R3 16 17 18
>
> want to do t.test using each column (with same name ) using Matrix1 and
Matrix2
>
> for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value

I am not sure if it is a best way but here seems to me that for cycle
could be considered

result<-rep(NA, 3999)
for (i in 2:4000) {
result [i-1] <- t.test(mat1[,i], mat2[,i])$p.value
}

Regards
Petr

>
> What is the best way to do it. I have dataset with 4000 columns for each

> matrix with same row and column names.
>
> Thanks a lot.
>
> ---------------------------------
> Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try
it now.
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

t.test : extracting Error

mogra
In reply to this post by pinal
Hi Thanks for the reply.

I implemented your solution to my problem but ...

For some of my column there is not enough data to do t-test so it gives me error and stops the for loop, is any graceful way to check for error msg and say ok if there is no $p.value continue to the next column

Once again thx for help.


sata pinal wrote
I have two matrix with same dimensions. I want to do t.test using each column from 2 different matrix.  
Row n Column names in both matrix are same.
 
e.g.  
Matrix1      
id VC1 VC2 VC3      
R 1 2 3    
R1 4 5 6    
R3 7 8 9  
 
 
Matrix2    
id VC1 VC2 VC3
R 10 11 12
R1 13 14 15
R3 16 17 18
 
want to do t.test using each column (with same name ) using Matrix1 and Matrix2
 
for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
 
What is the best way to do it. I have dataset with 4000 columns for each matrix with same row and column names.
 
Thanks a lot.
       
---------------------------------
Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.
Reply | Threaded
Open this post in threaded view
|

Re: t.test : extracting Error

Uwe Ligges


mogra wrote:
> Hi Thanks for the reply.
>
> I implemented your solution to my problem but ...
>
> For some of my column there is not enough data to do t-test so it gives me
> error and stops the for loop, is any graceful way to check for error msg and
> say ok if there is no $p.value continue to the next column


See ?try

Uwe Ligges

> Once again thx for help.
>
>
>
> sata pinal wrote:
>> I have two matrix with same dimensions. I want to do t.test using each
>> column from 2 different matrix.  
>> Row n Column names in both matrix are same.
>>  
>> e.g.  
>> Matrix1      
>> id VC1 VC2 VC3      
>> R 1 2 3    
>> R1 4 5 6    
>> R3 7 8 9  
>>  
>>  
>> Matrix2    
>> id VC1 VC2 VC3
>> R 10 11 12
>> R1 13 14 15
>> R3 16 17 18
>>  
>> want to do t.test using each column (with same name ) using Matrix1 and
>> Matrix2
>>  
>> for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
>>  
>> What is the best way to do it. I have dataset with 4000 columns for each
>> matrix with same row and column names.
>>  
>> Thanks a lot.
>>        
>> ---------------------------------
>> Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try
>> it now.
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Reg : using two different matrix : how to do t.test

Moshe Olshansky-2
In reply to this post by pinal
Since t.test takes much more time than parsing loop, I
won't hesitate to do a loop on the columns.

--- sata pinal <[hidden email]> wrote:

> I have two matrix with same dimensions. I want to do
> t.test using each column from 2 different matrix.  
> Row n Column names in both matrix are same.
>  
> e.g.  
> Matrix1      
> id VC1 VC2 VC3      
> R 1 2 3    
> R1 4 5 6    
> R3 7 8 9  
>  
>  
> Matrix2    
> id VC1 VC2 VC3
> R 10 11 12
> R1 13 14 15
> R3 16 17 18
>  
> want to do t.test using each column (with same name
> ) using Matrix1 and Matrix2
>  
> for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
>  
> What is the best way to do it. I have dataset with
> 4000 columns for each matrix with same row and
> column names.
>  
> Thanks a lot.
>        
> ---------------------------------
> Be a better sports nut! Let your teams follow you
> with Yahoo Mobile. Try it now.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Reg : using two different matrix : how to do t.test

Weiwei Shi
In reply to this post by pinal
sapply(1:4000, function(k){
   t.test(Matrix1[,k], Matrix2[,k])$p.value
})


I did not test, though.

HTH,

Weiwei

On 11/19/07, sata pinal <[hidden email]> wrote:

> I have two matrix with same dimensions. I want to do t.test using each column from 2 different matrix.
> Row n Column names in both matrix are same.
>
> e.g.
> Matrix1
> id VC1 VC2 VC3
> R 1 2 3
> R1 4 5 6
> R3 7 8 9
>
>
> Matrix2
> id VC1 VC2 VC3
> R 10 11 12
> R1 13 14 15
> R3 16 17 18
>
> want to do t.test using each column (with same name ) using Matrix1 and Matrix2
>
> for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
>
> What is the best way to do it. I have dataset with 4000 columns for each matrix with same row and column names.
>
> Thanks a lot.
>
> ---------------------------------
> Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now.
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>


--
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Odp: t.test : extracting Error

PIKAL Petr
In reply to this post by mogra
Hi

[hidden email] napsal dne 20.11.2007 09:36:32:

>
> Hi Thanks for the reply.
>
> I implemented your solution to my problem but ...
>
> For some of my column there is not enough data to do t-test so it gives
me
> error and stops the for loop, is any graceful way to check for error msg
and
> say ok if there is no $p.value continue to the next column

You need at least 2 values for x and 2 values for y so you can just put an
if clause in your for loop. Something like:

for (whatever) {
if(sum(!is.na(x)>1 & sum(!is.na(y)>1) do your t.test
}

Regards
Petr


>
> Once again thx for help.
>
>
>
> sata pinal wrote:
> >
> > I have two matrix with same dimensions. I want to do t.test using each
> > column from 2 different matrix.
> > Row n Column names in both matrix are same.
> >
> > e.g.
> > Matrix1
> > id VC1 VC2 VC3
> > R 1 2 3
> > R1 4 5 6
> > R3 7 8 9
> >
> >
> > Matrix2
> > id VC1 VC2 VC3
> > R 10 11 12
> > R1 13 14 15
> > R3 16 17 18
> >
> > want to do t.test using each column (with same name ) using Matrix1
and
> > Matrix2
> >
> > for eg t.test(Matrix1$VC1, Matrix2$VC1)$p.value
> >
> > What is the best way to do it. I have dataset with 4000 columns for
each
> > matrix with same row and column names.
> >
> > Thanks a lot.
> >
> > ---------------------------------
> > Be a better sports nut! Let your teams follow you with Yahoo Mobile.
Try

> > it now.
> >    [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
> >
> >
>
> --
> View this message in context:
http://www.nabble.com/Reg-%3A-%09using-two-
> different-matrix-%3A-how-to-do-t.test-tf4834072.html#a13845405
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.