Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying threshold on correlation matrix in R

Tags:

r

I am currently working on a dataset using R. I have created a correlation martix(Pearson) for my variables.But now I want to put a threshold for the values shown in matrix. I am trying the following code:

cor_relation = cor(mydata_frame, use="all.obs", method="pearson")

I get the following output:

             200605_s_at      202592_at      202958_at
200605_s_at  1.000000000     0.295065389     0.169772244
202592_at    0.695065389     1.000000000     -0.534394180
202958_at    0.869772244     -0.534394180    1.000000000

I want to find the following output(when i put the threshold 0.6):

             200605_s_at      202592_at      202958_at
200605_s_at  1.000000000        NA              NA
202592_at    0.695065389     1.000000000        NA
202958_at    0.869772244        NA           1.000000000

Thanks in advance for help!

like image 671
jessy Avatar asked Sep 04 '25 17:09

jessy


1 Answers

An alternate:

cor_relation[abs(cor_relation) < 0.6] <- NA
like image 185
BrodieG Avatar answered Sep 07 '25 05:09

BrodieG