reorder correlation matrix, according to the coefficients, using the hierarchical clustering method.
cor_reorder(x)
a correlation matrix. Particularly, an object of class cor_mat
.
a data frame
cor_mat()
, cor_gather()
, cor_spread()
# Compute correlation matrix
#::::::::::::::::::::::::::::::::::::::::::
cor.mat <- mtcars %>%
select(mpg, disp, hp, drat, wt, qsec) %>%
cor_mat()
# Reorder by correlation and get p-values
#::::::::::::::::::::::::::::::::::::::::::
# Reorder
cor.mat %>%
cor_reorder()
#> # A tibble: 6 × 7
#> rowname hp disp wt qsec mpg drat
#> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 hp 1 0.79 0.66 -0.71 -0.78 -0.45
#> 2 disp 0.79 1 0.89 -0.43 -0.85 -0.71
#> 3 wt 0.66 0.89 1 -0.17 -0.87 -0.71
#> 4 qsec -0.71 -0.43 -0.17 1 0.42 0.091
#> 5 mpg -0.78 -0.85 -0.87 0.42 1 0.68
#> 6 drat -0.45 -0.71 -0.71 0.091 0.68 1
# Get p-values of the reordered cor_mat
cor.mat %>%
cor_reorder() %>%
cor_get_pval()
#> # A tibble: 6 × 7
#> rowname hp disp wt qsec mpg drat
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 hp 0 7.14e- 8 4.15e- 5 0.00000577 1.79e- 7 0.00999
#> 2 disp 0.0000000714 0 1.22e- 11 0.0131 9.38e-10 0.00000528
#> 3 wt 0.0000415 1.22e-11 2.27e-236 0.339 1.29e-10 0.00000478
#> 4 qsec 0.00000577 1.31e- 2 3.39e- 1 0 1.71e- 2 0.62
#> 5 mpg 0.000000179 9.38e-10 1.29e- 10 0.0171 0 0.0000178
#> 6 drat 0.00999 5.28e- 6 4.78e- 6 0.62 1.78e- 5 0