Title: | Creates and Saves Out a Correlation Table with Significance Levels Indicated |
Version: | 0.1.1 |
Description: | After using this, a publication-ready correlation table with p-values indicated will be created. The input can be a full data frame; any string and Boolean terms will be dropped as part of functionality. Correlations and p-values are calculated using the 'Hmisc' framework. Output of the correlation_matrix() function is a table of strings; this gets saved out to a '.csv2' with the save_correlation_matrix() function for easy insertion into a paper. For more details about the process, consult https://paulvanderlaken.com/2020/07/28/publication-ready-correlation-matrix-significance-r/. |
License: | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.1 |
Imports: | Hmisc |
Suggests: | waldo, withr, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2023-11-02 18:08:40 UTC; laycocla |
Author: | Paul van der Laken
|
Maintainer: | Laura Lambert <laura.lambert.99@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-11-02 19:30:02 UTC |
Creates a publication-ready / formatted correlation matrix, using Hmisc::rcorr
in the backend.
Description
Creates a publication-ready / formatted correlation matrix, using Hmisc::rcorr
in the backend.
Usage
correlation_matrix(
df,
type = "pearson",
digits = 3,
decimal.mark = ".",
use = "all",
show_significance = TRUE,
replace_diagonal = FALSE,
replacement = ""
)
Arguments
df |
dataframe; containing numeric and/or logical columns to calculate correlations for |
type |
character; specifies the type of correlations to compute; gets passed to |
digits |
integer/double; number of decimals to show in the correlation matrix; gets passed to |
decimal.mark |
character; which decimal.mark to use; gets passed to |
use |
character; which part of the correlation matrix to display; options are |
show_significance |
boolean; whether to add |
replace_diagonal |
boolean; whether to replace the correlations on the diagonal; defaults to |
replacement |
character; what to replace the diagonal and/or upper/lower triangles with; defaults to |
Value
a correlation matrix
Examples
correlation_matrix(iris)
correlation_matrix(mtcars)
Creates and save to file a fully formatted correlation matrix, using correlation_matrix
and Hmisc::rcorr
in the backend
Description
Creates and save to file a fully formatted correlation matrix, using correlation_matrix
and Hmisc::rcorr
in the backend
Usage
save_correlation_matrix(df, filename, ...)
Arguments
df |
dataframe; passed to |
filename |
either a character string naming a file or a connection open for writing. "" indicates output to the console; passed to |
... |
any other arguments passed to |
Value
'csv' file. No value is returned.
Examples
save_correlation_matrix(df = iris,
filename = 'iris-correlation-matrix.csv')
save_correlation_matrix(df = mtcars,
filename = 'mtcars-correlation-matrix.csv',
digits = 3,
use = 'lower')