avoid within table correlations in rcorr
1
0
Entering edit mode
7.8 years ago
Edalat ▴ 30

I´m building a correlation between two different matrices(coding-lncoding) with rcorr() function in R,how can I remove within table correlations?is there any way or I should remove them by hand?

rcorr correlation • 2.8k views
ADD COMMENT
0
Entering edit mode

What specifically do you call within table correlation?

ADD REPLY
0
Entering edit mode

see this table that made by another person:

table1 <- matrix(rnorm(25),5)

table2 <- matrix(rnorm(25),5)

res <- rcorr(table1, table2, type="pearson") res

       [,1]  [,2]  [,3]  [,4]  [,5]  | [,6]  [,7]  [,8]  [,9] [,10]
# [1,]  1.00 -0.55  0.95 -0.16  0.17 |-0.46  0.15  0.10  0.69  0.16
# [2,] -0.55  1.00 -0.55 -0.60 -0.79 |-0.45 -0.66 -0.22 -0.30  0.12
# [3,]  0.95 -0.55  1.00 -0.09  0.30 |-0.35 -0.05 -0.17  0.57 -0.03
# [4,] -0.16 -0.60 -0.09  1.00  0.91 | 0.92  0.53 -0.21 -0.58 -0.71
# [5,]  0.17 -0.79  0.30  0.91  1.00 | 0.78  0.41 -0.31 -0.32 -0.68
# ------------------------------------------------------------------
# [6,] -0.46 -0.45 -0.35  0.92  0.78 | 1.00  0.44 -0.14 -0.62 -0.58
# [7,]  0.15 -0.66 -0.05  0.53  0.41 | 0.44  1.00  0.68  0.13  0.13
# [8,]  0.10 -0.22 -0.17 -0.21 -0.31 |-0.14  0.68  1.00  0.59  0.80
# [9,]  0.69 -0.30  0.57 -0.58 -0.32 |-0.62  0.13  0.59  1.00  0.80
#[10,]  0.16  0.12 -0.03 -0.71 -0.68 |-0.58  0.13  0.80  0.80  1.00
# pvalues to follow ...

Notice the upper right quadrant of rcorr() (which repeats diagonally symmetrical on lower left) is the entire result of cor() (rounded to two decimal points)

res <- cor(table1, table2, method="pearson")

res

#            [,1]        [,2]       [,3]       [,4]        [,5]
# [1,] -0.4551474  0.15080994  0.1008215  0.6894955  0.16390813
# [2,] -0.4468285 -0.66209106 -0.2154960 -0.2954581  0.11662382
# [3,] -0.3542023 -0.05474287 -0.1720881  0.5669501 -0.02880113
# [4,]  0.9246330  0.53456574 -0.2084105 -0.5807386 -0.71108552
# [5,]  0.7788395  0.40551828 -0.3122606 -0.3209273 -0.67912147

I want the correlation like core result,I need p-value so I used rcorr() function.

ADD REPLY
1
Entering edit mode
7.6 years ago
jpgsabino • 0

Hello,

You can try this:

table1 <- matrix(rnorm(25),5)

table2 <- matrix(rnorm(25),5)

cor.matrix <- rcorr(table1, table2, type="pearson")

P <- data.frame(cor.matrix$P)
R <- data.frame(cor.matrix$r)

# Data frame with p values
P.df <- P[,-c(1:ncol(table1))]
P.df <- P.df[-c((ncol(table1))+1:ncol(P)),]
P.df

# Data frame with r values
R.df <- R[,-c(1:ncol(table1))]
R.df <- R.df[-c((ncol(table1))+1:ncol(R)),]
R.df

Grts

ADD COMMENT

Login before adding your answer.

Traffic: 2581 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6