cor.test for several parameters - automated Spearman rank correlations?

Is there a way to automate the cor.test command (or extend it) for several variables? For example if you have 10 variables and you are interested in the correlation of each variable with each of the other variables - would you then have to repeat the cor.test command for each combination of variables or does a shortcut exist? I'm using RStudio version 3.5.2.

Hi there,

If you can provide some data I'd be happy to help you :slight_smile: See how to make a reprex here: FAQ: How to do a minimal reproducible example ( reprex ) for beginners

Thank you! I have reduced my dataset, but this is an example:

data <- data.frame(
VL=c(1,2,3,4,5,6,7,8,9,10),
AL=c(1,1,1,1,1,2,2,2,2,2),
RA=c(1,2,3,4,5,1,2,3,4,5),
DI=c(2.8,2.3,2.2,2.7,1.4,1.6,0.6,0.7,1.0,1.3),
TI=c(2.57,2.62,2.61,2.39,1.76,2.05,2.26,2.29,2.19,2.85),
SI=c(1.82,1.83,1.82,1.66,1.61,1.53,1.79,1.75,1.81,1.98),
TI_SI=c(2.2,2.23,2.22,2.03,1.69,1.79,2.03,2.02,2.00,2.42)
)

Then I make a correlation matrix:
matrix <- as.dist(round(cor(data,method="spearman"),2))

And now I want to test the correlations, but don't know how to do it automated as described in my post.

Have a look here so long: Pair wise cor.test based on combinations of variables

When I get time I will look at your data and see how best to do it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.