epi_stats_corr: Get a correlation matrix with p-values

Description Usage Arguments Value Author(s) See Also Examples

View source: R/epi_stats_corr.R

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

1
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 <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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## 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 Nov. 7, 2019, 5:34 p.m.