Convert a correlation test data frame, returned by the cor_test(), into a correlation matrix format.

as_cor_mat(x)

Arguments

x

an object of class cor_test.

Value

Returns a data frame containing the matrix of the correlation coefficients. The output has an attribute named "pvalue", which contains the matrix of the correlation test p-values.

See also

Examples

# Pairwise correlation tests between variables #::::::::::::::::::::::::::::::::::::::::::::::: res.cor.test <- mtcars %>% select(mpg, disp, hp, drat, wt, qsec) %>% cor_test() res.cor.test
#> # A tibble: 36 x 8 #> var1 var2 cor statistic p conf.low conf.high method #> * <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> #> 1 mpg mpg 1 Inf 0. 1 1 Pearson #> 2 mpg disp -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson #> 3 mpg hp -0.78 -6.74 1.79e- 7 -0.885 -0.586 Pearson #> 4 mpg drat 0.68 5.10 1.78e- 5 0.436 0.832 Pearson #> 5 mpg wt -0.87 -9.56 1.29e-10 -0.934 -0.744 Pearson #> 6 mpg qsec 0.42 2.53 1.71e- 2 0.0820 0.670 Pearson #> 7 disp mpg -0.85 -8.75 9.38e-10 -0.923 -0.708 Pearson #> 8 disp disp 1 Inf 0. 1 1 Pearson #> 9 disp hp 0.79 7.08 7.14e- 8 0.611 0.893 Pearson #> 10 disp drat -0.71 -5.53 5.28e- 6 -0.849 -0.481 Pearson #> # … with 26 more rows
# Convert the correlation test into a correlation matrix #::::::::::::::::::::::::::::::::::::::::::::::: res.cor.test %>% as_cor_mat()
#> # A tibble: 6 x 7 #> rowname mpg disp hp drat wt qsec #> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 mpg 1 -0.85 -0.78 0.68 -0.87 0.42 #> 2 disp -0.85 1 0.79 -0.71 0.89 -0.43 #> 3 hp -0.78 0.79 1 -0.45 0.66 -0.71 #> 4 drat 0.68 -0.71 -0.45 1 -0.71 0.091 #> 5 wt -0.87 0.89 0.66 -0.71 1 -0.17 #> 6 qsec 0.42 -0.43 -0.71 0.091 -0.17 1