Question

I have used rcorr() from Hmisc for doing multiple correlations (on about 500 x 40 large data frames). This command returns a list, but I saved only what I needed in the list as data frames. Thus, I have two data frames, one with Pearson rho and one with the p-values. Everything are identical between the data frames, but the cell values.

AdiASigFatCorr <- rcorr(as.matrix(AdiASigFat), type=c("pearson"))
AdiASigFatCorrP <- as.data.frame(AdiASigFatCorr$P)
AdiASigFatCorrR <- as.data.frame(AdiASigFatCorr$r)

Now, I want to keep only the rho values that have p-value < 0.05. Here is a glimt from the two data frames:

AdiASigFatCorrP (p-values):

            pre_ISI.kg_  pre_ISI.mmol pre_Weight
pre_BMP3    0.0002293035 0.0006511392 0.043833537
pre_CES1    0.0604775694 0.0791677406 0.076397970
pre_CETP    0.0336650792 0.0641110946 0.361560818

AdiASigFatCorrR (rho values):

              pre_ISI.kg_  pre_ISI.mmol pre_Weight
pre_BMP3      0.6838388    0.6459200 -0.4148415
pre_CES1     -0.3887246   -0.3653443  0.3685230
pre_CETP      0.4349413    0.3837841 -0.1948498

I want to subset the rho value if the corresponding p-value < 0.05.

I have read a lot and tried many different approaches using subset() etc., but I, totally stuck..

And if there are other methods/packages made for this purpose, please enlighten me.

Thank you!

Was it helpful?

Solution

Calling the rho matrix corr.rho and the p-value matrix corr.p, you can use simple vector operations to find all the values of corr.rho such that corr.p < 0.05. If the data is not in matrix form already, it can be coerced to a matrix with as.matrix

> corr.rho[corr.p < 0.05]
[1]  0.6838388  0.4349413  0.6459200 -0.4148415
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top