cor_df
calculate correlation matrix/stripe for each complete pairs.
cor_df(dat, tar.column = NULL, method = "pearson", nice.format = FALSE)
a dataframe, include *only* numeric columns for correlation
default is `NULL`, when set to *one string of a column name*, then extract the output only related to this column.
default is `FALSE`, when `TRUE`, then arrange with `r2` and subset for the significance one.
default is 'pearson', 'spearman' and 'sma' is also available
a list of three elements: 1. `r.mat`r matrix, 2.`p.mat` p-value matrix or a dataframe containing `r`,`r2`,`sign`,`p`,`p.value`,`p.sig`.
# numeric dataframe
cor_df(mtcars[,1:3])
#> using pearson correlation of coefficient
#> $r.value
#> mpg cyl disp
#> mpg 1.0000000 -0.8521620 -0.8475514
#> cyl -0.8521620 1.0000000 0.9020329
#> disp -0.8475514 0.9020329 1.0000000
#>
#> $p.value
#> mpg cyl disp
#> mpg 0.000000e+00 6.112687e-10 9.380327e-10
#> cyl 6.112687e-10 0.000000e+00 1.802838e-12
#> disp 9.380327e-10 1.802838e-12 0.000000e+00
#>
cor_df(mtcars,"cyl")
#> using pearson correlation of coefficient
#> from to r r2 sign p p.sig
#> 1 mpg cyl -0.8521620 0.7261800 - 6.112687e-10 ***
#> 2 disp cyl 0.9020329 0.8136633 + 1.802838e-12 ***
#> 3 hp cyl 0.8324475 0.6929688 + 3.477861e-09 ***
#> 4 drat cyl -0.6999381 0.4899134 - 8.244636e-06 ***
#> 5 wt cyl 0.7824958 0.6122997 + 1.217567e-07 ***
#> 6 qsec cyl -0.5912421 0.3495672 - 3.660533e-04 ***
#> 7 vs cyl -0.8108118 0.6574158 - 1.843018e-08 ***
#> 8 am cyl -0.5226070 0.2731181 - 2.151207e-03 **
#> 9 gear cyl -0.4926866 0.2427401 - 4.173297e-03 **
#> 10 carb cyl 0.5269883 0.2777167 + 1.942340e-03 **
cor_df(mtcars,"cyl",nice.format=T)
#> using pearson correlation of coefficient
#> from to r r2 sign p p.sig
#> 1 disp cyl 0.9 0.81 + 1.8e-12 ***
#> 2 mpg cyl -0.85 0.73 - 6.1e-10 ***
#> 3 hp cyl 0.83 0.69 + 3.5e-09 ***
#> 4 vs cyl -0.81 0.66 - 1.8e-08 ***
#> 5 wt cyl 0.78 0.61 + 1.2e-07 ***
#> 6 drat cyl -0.7 0.49 - 8.2e-06 ***
#> 7 qsec cyl -0.59 0.35 - 4e-04 ***
#> 8 carb cyl 0.53 0.28 + 0.002 **
#> 9 am cyl -0.52 0.27 - 0.002 **
#> 10 gear cyl -0.49 0.24 - 0.004 **
cor_df(mtcars,"cyl",nice.format=T,method='sma')
#> using sma correlation of coefficient
#> from to r r2 sign p p.sig
#> 1 disp cyl 0.9 0.81 + 1.8e-12 ***
#> 2 mpg cyl -0.85 0.73 - 6.1e-10 ***
#> 3 hp cyl 0.83 0.69 + 3.5e-09 ***
#> 4 vs cyl -0.81 0.66 - 1.8e-08 ***
#> 5 wt cyl 0.78 0.61 + 1.2e-07 ***
#> 6 drat cyl -0.7 0.49 - 8.2e-06 ***
#> 7 qsec cyl -0.59 0.35 - 4e-04 ***
#> 8 carb cyl 0.53 0.28 + 0.002 **
#> 9 am cyl -0.52 0.27 - 0.002 **
#> 10 gear cyl -0.49 0.24 - 0.004 **
# dataframe contains character
cor_df(iris)
#> Error in cor_df(iris): data contains factor columns
cor_df(iris[,-5])
#> using pearson correlation of coefficient
#> $r.value
#> Sepal.Length Sepal.Width Petal.Length Petal.Width
#> Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
#> Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
#> Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
#> Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000
#>
#> $p.value
#> Sepal.Length Sepal.Width Petal.Length Petal.Width
#> Sepal.Length 0.000000e+00 1.518983e-01 1.038667e-47 2.325498e-37
#> Sepal.Width 1.518983e-01 0.000000e+00 4.513314e-08 4.073229e-06
#> Petal.Length 1.038667e-47 4.513314e-08 0.000000e+00 4.675004e-86
#> Petal.Width 2.325498e-37 4.073229e-06 4.675004e-86 0.000000e+00
#>