epi_stats_corr: Get a correlation matrix with p-values

View source: R/epi_stats_corr.R

epi_stats_corrR Documentation

Get a correlation matrix with p-values

Description

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.

Usage

epi_stats_corr(df = NULL, method = "spearman")

Arguments

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'

Value

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).

Author(s)

Antonio Berlanga-Taylor <\url{https://github.com/AntonioJBT/episcout}>

See Also

epi_stats_corr_triangle, epi_stats_corr_rename, epi_plot_heatmap, epi_plot_heatmap_triangle, rcorr, melt.

Examples


## 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)


AntonioJBT/episcout documentation built on June 8, 2024, 7:47 a.m.