1

I'm using rcorr to correlate 54 items by 24.

Don't worry, I'm aware this is a lot of correlations and may need to perform extra stats to account for this. This is mostly to get a feel for my data.

Using rcorr I want to cut the produced table down to just the p values under .05. I'm not interested in any correlation of items over this. What would that command look like? Right now this is the command I'm using

library(Hmisc)
x=matrix(sample.int(7, size = 100*79, replace = TRUE), nrow = 100, ncol = 79)
rcorr(as.matrix(x[,2:25]),as.matrix(x[,26:79]))

I've run a PCA of all the items as well to see how they load together but I also want to see the correlations.

Vlo
  • 3,168
  • 13
  • 27
  • 5
    Please read about how to provide [a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that includes packages, example data, and code. – Thomas Aug 04 '14 at 10:41
  • Thanks. So if we're just creating a matrix with a scale of 1:7, 100 participants, and 79 categories then I believe it would be done as follows: library(Hmisc) x=matrix(sample.int(7, size = 100*79, replace = TRUE), nrow = 100, ncol = 79) rcorr(as.matrix(x[,2:25]),as.matrix(x[,26:79])) I'm looking to only take the correlations with p<.05. – postgraduatestudent Aug 04 '14 at 12:27
  • 1
    Please do not post unformatted code in comments. It is much better to edit your question so that everything is readable. – Thomas Aug 04 '14 at 13:04
  • What does 'cut' mean? If you want to keep the p < 0.05, what do you do with the other values on the same row/column? Let your rcorr output be `z`. If you want logical do `z$P < 0.05`, if you want the index do `which(z$P < 0.05)` – Vlo Aug 04 '14 at 13:44

1 Answers1

1

I'm sure that Frank Harrell would be horrified by this since he is justly famous for pointing gut that this sort of multiple testing maneuver will fail to be a valid basis for inference, but as a programming exercise this might be useful:

pres <- rcorr(as.matrix(x[,2:25]),as.matrix(x[,26:79]))$P
is.na(pres) <- pres < 0.05
pres

If instead of presenting in a matrix format you wanted the row and column numbers of such values, it would be:

 which( pres < 0.05, arr.ind=TRUE )

(Please, Frank, forgive them for they know not what they do.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487