epi_stats_corr_triangle: Get the lower triangle from a correlation matrix

View source: R/epi_stats_corr_triangle.R

epi_stats_corr_triangleR Documentation

Get the lower triangle from a correlation matrix

Description

Keep only the lower triangle of the correlation matrix Useful to create a nicer heatmap. Requires the original, unmelted correlation matrix with both correlation (r) and p-values (P).

Usage

epi_stats_corr_triangle(cormat = "cormat_all$cormat")

Arguments

cormat

a matrix object (usually the output of Hmisc::rcorr() or episcout::epi_stats_corr()). Default 'cormat_all$cormat'

Value

Returns a list object melted_triangles containing the lower triangle of the correlation matrix (cormat) with the correlation (cormat_melted_triangle_r) and p-values (cormat_melted_triangle_pval).

Author(s)

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

See Also

epi_stats_corr, epi_stats_corr_rename, epi_plot_heatmap, epi_plot_heatmap_triangle, rcorr, melt

Examples


## Not run: 
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')
melted_triangles <- epi_stats_corr_triangle(cormat = cormat_all$cormat)
melted_triangles$cormat_melted_triangle_r
melted_triangles$cormat_melted_triangle_pval
class(melted_triangles)

## End(Not run)

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