Re-arrange a correlation data frame to group highly correlated variables closer together.

rearrange(x, method = "PC", absolute = TRUE)

Arguments

x

cor_df. See correlate.

method

String specifying the arrangement (clustering) method. Clustering is achieved via seriate, which can be consulted for a complete list of clustering methods. Default = "PCA".

absolute

Boolean whether absolute values for the correlations should be used for clustering.

Value

cor_df. See correlate.

Examples

x <- correlate(mtcars)
#> #> Correlation method: 'pearson' #> Missing treated using: 'pairwise.complete.obs'
rearrange(x) # Default settings
#> # A tibble: 11 x 12 #> term mpg vs drat am gear qsec carb hp wt #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mpg NA 0.664 0.681 0.600 0.480 0.419 -0.551 -0.776 -0.868 #> 2 vs 0.664 NA 0.440 0.168 0.206 0.745 -0.570 -0.723 -0.555 #> 3 drat 0.681 0.440 NA 0.713 0.700 0.0912 -0.0908 -0.449 -0.712 #> 4 am 0.600 0.168 0.713 NA 0.794 -0.230 0.0575 -0.243 -0.692 #> 5 gear 0.480 0.206 0.700 0.794 NA -0.213 0.274 -0.126 -0.583 #> 6 qsec 0.419 0.745 0.0912 -0.230 -0.213 NA -0.656 -0.708 -0.175 #> 7 carb -0.551 -0.570 -0.0908 0.0575 0.274 -0.656 NA 0.750 0.428 #> 8 hp -0.776 -0.723 -0.449 -0.243 -0.126 -0.708 0.750 NA 0.659 #> 9 wt -0.868 -0.555 -0.712 -0.692 -0.583 -0.175 0.428 0.659 NA #> 10 disp -0.848 -0.710 -0.710 -0.591 -0.556 -0.434 0.395 0.791 0.888 #> 11 cyl -0.852 -0.811 -0.700 -0.523 -0.493 -0.591 0.527 0.832 0.782 #> # … with 2 more variables: disp <dbl>, cyl <dbl>
rearrange(x, method = "HC") # Different seriation method
#> # A tibble: 11 x 12 #> term carb hp wt cyl disp drat am gear qsec #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 carb NA 0.750 0.428 0.527 0.395 -0.0908 0.0575 0.274 -0.656 #> 2 hp 0.750 NA 0.659 0.832 0.791 -0.449 -0.243 -0.126 -0.708 #> 3 wt 0.428 0.659 NA 0.782 0.888 -0.712 -0.692 -0.583 -0.175 #> 4 cyl 0.527 0.832 0.782 NA 0.902 -0.700 -0.523 -0.493 -0.591 #> 5 disp 0.395 0.791 0.888 0.902 NA -0.710 -0.591 -0.556 -0.434 #> 6 drat -0.0908 -0.449 -0.712 -0.700 -0.710 NA 0.713 0.700 0.0912 #> 7 am 0.0575 -0.243 -0.692 -0.523 -0.591 0.713 NA 0.794 -0.230 #> 8 gear 0.274 -0.126 -0.583 -0.493 -0.556 0.700 0.794 NA -0.213 #> 9 qsec -0.656 -0.708 -0.175 -0.591 -0.434 0.0912 -0.230 -0.213 NA #> 10 mpg -0.551 -0.776 -0.868 -0.852 -0.848 0.681 0.600 0.480 0.419 #> 11 vs -0.570 -0.723 -0.555 -0.811 -0.710 0.440 0.168 0.206 0.745 #> # … with 2 more variables: mpg <dbl>, vs <dbl>
rearrange(x, absolute = FALSE) # Not using absolute values for arranging
#> # A tibble: 11 x 12 #> term mpg vs drat am gear qsec carb hp wt #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mpg NA 0.664 0.681 0.600 0.480 0.419 -0.551 -0.776 -0.868 #> 2 vs 0.664 NA 0.440 0.168 0.206 0.745 -0.570 -0.723 -0.555 #> 3 drat 0.681 0.440 NA 0.713 0.700 0.0912 -0.0908 -0.449 -0.712 #> 4 am 0.600 0.168 0.713 NA 0.794 -0.230 0.0575 -0.243 -0.692 #> 5 gear 0.480 0.206 0.700 0.794 NA -0.213 0.274 -0.126 -0.583 #> 6 qsec 0.419 0.745 0.0912 -0.230 -0.213 NA -0.656 -0.708 -0.175 #> 7 carb -0.551 -0.570 -0.0908 0.0575 0.274 -0.656 NA 0.750 0.428 #> 8 hp -0.776 -0.723 -0.449 -0.243 -0.126 -0.708 0.750 NA 0.659 #> 9 wt -0.868 -0.555 -0.712 -0.692 -0.583 -0.175 0.428 0.659 NA #> 10 disp -0.848 -0.710 -0.710 -0.591 -0.556 -0.434 0.395 0.791 0.888 #> 11 cyl -0.852 -0.811 -0.700 -0.523 -0.493 -0.591 0.527 0.832 0.782 #> # … with 2 more variables: disp <dbl>, cyl <dbl>