Home > database >  How can I make an asymmetric correlation in r?
How can I make an asymmetric correlation in r?

Time:05-04

Sometimes I used to use psych::corr.test function with two data frames like:

df1 <- tibble(a=c(1,2,4,5,67,21,21,65,1,5), b=c(21,5,2,6,8,4,2,6,2,2))

df2 <- tibble(a=c(1,2,3,4,5,6,7,8,9,8), b=c(1,6,54,8,3,8,9,5,2,1), c=c(1,4,6,8,5,3,9,7,5,4))

corr <- corr.test(df1,df2, adjust = "BH")

And I was getting p-values from corr$p.adj But sometimes it gives me strange repetitive p.values like:

          a         b         c
a 0.5727443 0.5964993 0.5727443
b 0.2566757 0.5727443 0.2566757

Does anyone know how adequate these p-values are? Can we do this with the corr.test? If not, how can I make an asymmetric correlation?

I'm stressed that if I try to perform symmetric correlation like

df <- bind_cols(df1,df2[-3])
corr <- corr.test(df, adjust = "BH")

it's p-values not so repetative:

Probability values (Entries above the diagonal are adjusted for multiple tests.) 
      a...1 b...2 a...3 b...4
a...1  0.00  0.97  0.62  0.72
b...2  0.97  0.00  0.38  0.62
a...3  0.39  0.06  0.00  0.62
b...4  0.60  0.40  0.41  0.00

UPD: Okay, I realised that it's as repetitive as the first and I'm a bit stupid.

CodePudding user response:

The BH correction is based on computing the cumulative minimum of n/i * p, where the p has your n = 6 unadjusted p-values in decreasing order, and i is 6:1. (You can see the calculation in psych::p.adjust.)

Because it's a cumulative minimum (i.e. the first value, then the min of the first and second, then the min of the first to third, etc.) there are likely to be repetitions.

  • Related