From a data.frame object it gives a correlation matrix formatted for overview

nice_corrmatrix(
  cr,
  group = NULL,
  upper = FALSE,
  lower = TRUE,
  digits = 2,
  show_r = TRUE,
  show_p = FALSE,
  show_stars = TRUE,
  show_ci = FALSE,
  numbered_columns = TRUE,
  show_descriptives = TRUE,
  labels = "auto",
  nsig_p = 0.1,
  char_nsig,
  char_autocor = "-",
  char_p10 = "✞",
  char_NA = "",
  string_ci = "{break_sign}[{ci_lower},{ci_upper}]",
  string_p = "{break_sign}(p {nice_p(p, equal_sign = TRUE)})",
  caption = NULL,
  drop_zero = TRUE,
  type = "html",
  file = NULL,
  ...
)

Arguments

cr

A data frame

group

a vector with a grouping variable or a character with a variable name. If included, calculates multilevel correlations.

upper

TRUE if upper triangle should be included.

lower

TRUE if lower triangle should be included.

digits

Round to given digit position.

show_r

TRUE if r-values should be included.

show_p

TRUE if r-values should be included.

show_stars

TRUE if stars should be included.

show_ci

If TRUE, confidence intervals are added.

labels

Character string. If "auto" labels are taken from a label attribute.

nsig_p

p level below which correlations are considered not significant.

char_nsig

Character indexing non-significant values.

char_autocor

Character for diagonal (e.g. "-" or "1.00").

char_p10

Character indexing .10 significance level.

char_NA

Character for NA values.

string_ci

Character string in glue format for confindence internvals.

string_p

Character string in glue format for p-values.

caption

Caption for an html table.

drop_zero

If TRUE, leadning zeros are dropped.

type

Character string. "df" for data-frame. "html" for html table.

file

If TRUE or a filename is provided, a file is exportet (format is defined by file ending eith html or docx).

...

Further arguments passed to the cor.test() function.

show_discriptives

If TRUE, mean and sd columns are added.

Value

A data-frame or a html table object

Examples

nice_corrmatrix(mtcars)
Table
Correlation matrix
Variable n M SD 1 2 3 4 5 6 7 8 9 10 11
1. mpg 32 20.09 6.03
2. cyl 32 6.19 1.79 -.85***
3. disp 32 230.72 123.94 -.85*** .90***
4. hp 32 146.69 68.56 -.78*** .83*** .79***
5. drat 32 3.60 0.53 .68*** -.70*** -.71*** -.45**
6. wt 32 3.22 0.98 -.87*** .78*** .89*** .66*** -.71***
7. qsec 32 17.85 1.79 .42* -.59*** -.43* -.71*** .09 -.17
8. vs 32 0.44 0.50 .66*** -.81*** -.71*** -.72*** .44* -.55*** .74***
9. am 32 0.41 0.50 .60*** -.52** -.59*** -.24 .71*** -.69*** -.23 .17
10. gear 32 3.69 0.74 .48** -.49** -.56*** -.13 .70*** -.58*** -.21 .21 .79***
11. carb 32 2.81 1.62 -.55** .53** .39* .75*** -.09 .43* -.66*** -.57*** .06 .27
Note.p < .10; *p < .05; **p < .01; ***p < .001. .
nice_corrmatrix(mtcars, show_p = TRUE, show_ci = TRUE, show_stars = FALSE, show_descriptives = FALSE, conf.level = 0.99 )
Table
Correlation matrix
Variable 1 2 3 4 5 6 7 8 9 10 11
1. mpg
2. cyl -.85
[-.93,-.72]
(p <.001>
3. disp -.85
[-.92,-.71]
(p <.001>
.90
[.81,.95]
(p <.001>
4. hp -.78
[-.89,-.59]
(p <.001>
.83
[.68,.92]
(p <.001>
.79
[.61,.89]
(p <.001>
5. drat .68
[.44,.83]
(p <.001>
-.70
[-.84,-.46]
(p <.001>
-.71
[-.85,-.48]
(p <.001>
-.45
[-.69,-.12]
(p <.01>
6. wt -.87
[-.93,-.74]
(p <.001>
.78
[.60,.89]
(p <.001>
.89
[.78,.94]
(p <.001>
.66
[.40,.82]
(p <.001>
-.71
[-.85,-.48]
(p <.001>
7. qsec .42
[.08,.67]
(p <.05>
-.59
[-.78,-.31]
(p <.001>
-.43
[-.68,-.10]
(p <.05>
-.71
[-.85,-.48]
(p <.001>
.09
[-.27,.43]
(p =.620)
-.17
[-.49,.19]
(p =.339)
8. vs .66
[.41,.82]
(p <.001>
-.81
[-.90,-.64]
(p <.001>
-.71
[-.85,-.48]
(p <.001>
-.72
[-.86,-.50]
(p <.001>
.44
[.11,.68]
(p <.05>
-.55
[-.76,-.26]
(p <.001>
.74
[.53,.87]
(p <.001>
9. am .60
[.32,.78]
(p <.001>
-.52
[-.74,-.21]
(p <.01>
-.59
[-.78,-.31]
(p <.001>
-.24
[-.55,.12]
(p =.180)
.71
[.48,.85]
(p <.001>
-.69
[-.84,-.45]
(p <.001>
-.23
[-.54,.13]
(p =.206)
.17
[-.19,.49]
(p =.357)
10. gear .48
[.16,.71]
(p <.01>
-.49
[-.72,-.17]
(p <.01>
-.56
[-.76,-.26]
(p <.001>
-.13
[-.45,.23]
(p =.493)
.70
[.46,.84]
(p <.001>
-.58
[-.77,-.29]
(p <.001>
-.21
[-.52,.15]
(p =.243)
.21
[-.15,.52]
(p =.258)
.79
[.62,.89]
(p <.001>
11. carb -.55
[-.75,-.25]
(p <.01>
.53
[.22,.74]
(p <.01>
.39
[.05,.65]
(p <.05>
.75
[.54,.87]
(p <.001>
-.09
[-.43,.27]
(p =.621)
.43
[.09,.68]
(p <.05>
-.66
[-.82,-.40]
(p <.001>
-.57
[-.77,-.28]
(p <.001>
.06
[-.30,.40]
(p =.754)
.27
[-.08,.57]
(p =.129)
nice_corrmatrix(mtcars, group = "cyl") #> Error in `.rowNamesDF<-`(x, value = value): invalid 'row.names' length