View source: R/epi_stats_corr.R
epi_stats_corr | R Documentation |
Get a correlation matrix using Hmisc for many numerical variables. epi_stats_corr() wraps Hmisc::rcorr(), melts the matrix and returns correlation and p-values.
epi_stats_corr(df = NULL, method = "spearman")
df |
a data frame class object coerced to matrix and passed to Hmisc::rcorr() |
method |
should be a string that can be accepted by type parameter in Hmisc::rcorr(). 'Spearman' (default here) or 'pearson' |
Returns a list object cormat_all containing the correlation matrix (cormat), the melted correlation values (cormat_melted_r) (ie long format for plotting for example) and the melted p-values (cormat_melted_pval).
Antonio Berlanga-Taylor <\url{https://github.com/AntonioJBT/episcout}>
epi_stats_corr_triangle
,
epi_stats_corr_rename
,
epi_plot_heatmap
,
epi_plot_heatmap_triangle
,
rcorr
,
melt
.
## Not run:
library(Hmisc)
library(data.table)
df <- data.frame(var_id = rep(1:(n / 2), each = 2),
var_to_rep = rep(c("Pre", "Post"), n / 2),
x = rnorm(n),
y = rbinom(n, 1, 0.50),
z = rpois(n, 2)
)
epi_clean_count_classes(df)
df_corr <- df %>%select_if(~ epi_clean_cond_numeric(.))
df_corr <- df_corr[, -1] # exclude var_id
cormat_all <- epi_stats_corr(df_corr, method = 'pearson')
names(cormat_all)
names(cormat_all$cormat)
cormat_all$cormat$r
cormat_all$cormat_melted_r
class(cormat_all)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.