Re: Sorting a correlation matrix with R-statistics




Just a quick follow up to my own post. It looks like during the copy and paste of code and output, some errors occurred. So here is just the correct code and the final result. Also, for the sake of details, the third column in the initial data transformation by as.data.frame.table() is called 'Freq' by default. In the code below, I will rename it to 'Corr' for contextual consistency.


DF <- as.data.frame.table(cor(swiss), responseName = "Corr")

Top25 <- with(DF, DF[order(Corr, decreasing = TRUE)[1:25], ])

> Top25
Var1 Var2 Corr
1 Fertility Fertility 1.00000000
8 Agriculture Agriculture 1.00000000
15 Examination Examination 1.00000000
22 Education Education 1.00000000
29 Catholic Catholic 1.00000000
36 Infant.Mortality Infant.Mortality 1.00000000
16 Education Examination 0.69841530
21 Examination Education 0.69841530
5 Catholic Fertility 0.46368470
25 Fertility Catholic 0.46368470
6 Infant.Mortality Fertility 0.41655603
31 Fertility Infant.Mortality 0.41655603
11 Catholic Agriculture 0.40109505
26 Agriculture Catholic 0.40109505
2 Agriculture Fertility 0.35307918
7 Fertility Agriculture 0.35307918
30 Infant.Mortality Catholic 0.17549591
35 Catholic Infant.Mortality 0.17549591
12 Infant.Mortality Agriculture -0.06085861
32 Agriculture Infant.Mortality -0.06085861
24 Infant.Mortality Education -0.09932185
34 Education Infant.Mortality -0.09932185
18 Infant.Mortality Examination -0.11402160
33 Examination Infant.Mortality -0.11402160
23 Catholic Education -0.15385892

Apologies for the error.

Marc Schwartz
.


Loading