[R] Filtering matrices

bwgoudey bwgoudey at gmail.com
Wed Aug 26 04:54:33 CEST 2009


> r<-rcorr(d[[1]]) #d is matrix containing observation
> r[[1]] #r values
           age         sex         BMI
age  1.0000000 -0.30010322 -0.13702263
sex -0.3001032  1.00000000  0.06300528
BMI -0.1370226  0.06300528  1.00000000
> r[[2]] #Number of obervations
    age sex BMI
age 100 100 100
sex 100 100 100
BMI 100 100 100
> r[[3]] #P values
            age         sex       BMI
age          NA 0.002416954 0.1740134
sex 0.002416954          NA 0.5334484
BMI 0.174013354 0.533448366        NA

If I wanted to return a matrix containing all points where correlation was
above 0.75 and P-value was below 0.05, how would I do this?

Cheers
 Ben


Steve Lianoglou-6 wrote:
> 
> Hi,
> 
> On Tue, Aug 25, 2009 at 10:11 PM, bwgoudey<bwgoudey at gmail.com> wrote:
>>
>> I'm using the rcorr function from the Hmisc library to get pair-wise
>> correlations from a set of observations for a set of attributes. This
>> returns 3 matrices; one of correlations, one of the number of
>> observations
>> seen for each pair and the final of the P values for each correlation
>> seen.
>>
>> >From these three matrices, all I wish to do is return a single matrix
>> based
>> on the first correlation matrix where each value is above a certain
>> correlation, has a certain number of instances and has a P-value below
>> some
>> other threshold. My question is what is the nicest way of writing this
>> sort
>> of code?
> 
> Build some logical indexing vector against the matrix you want to pass
> the criteria against, and use that on the matrix that has your values.
> 
> If you need more help, please provide three small example matrices and
> let us know what you'd like your indexing to return. Someone will
> provide the code to show you the correct way to do it.
> 
> HTH,
> -steve
> 
> -- 
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> ______________________________________________
> R-help at 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Filtering-matrices-tp25145451p25145737.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list