epi_stats_corr_rename: Rename variables from melted triangles and convert to factors

View source: R/epi_stats_corr_rename.R

epi_stats_corr_renameR Documentation

Rename variables from melted triangles and convert to factors

Description

Rename variables from melted triangles and convert to factors for plotting. Requires correlation matrices with r and p-values with columns named 'Var1' and 'Var2'. The output of epi_stats_corr_triangle() can be used as input. Variables are converted to factors and re-labelled Values are rounded to digits (default is 2 so that they fit in the heatmap). The output can be used for prettier plotting.

Usage

epi_stats_corr_rename(
  r_vals = "melted_triangles$cormat_melted_triangle_r",
  p_vals = "melted_triangles$cormat_melted_triangle_pval",
  vars_list = vars_list,
  var_labels = var_labels,
  digits = 2
)

Arguments

r_vals

Correlation values in melted (long) format. Default is melted_triangles$cormat_melted_triangle_r

p_vals

p-values from correlations in melted (long) format. Default is melted_triangles$cormat_melted_triangle_pval

vars_list

List of variables to rename from 'Var1' and 'Var2'. Default is vars_list

var_labels

List of labels to use for renaming values from 'Var1' and 'Var2'. vars_list and var_labels must match by position. Default is var_labels

digits

Rounding integer for correlation and p-values. Default is 2

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) with the variables 'Var1' and 'Var2' converted to factors and re-labelled.

Note

vars_list and var_labels must match by position.

Author(s)

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

See Also

epi_stats_corr, epi_stats_corr_triangle, epi_plot_heatmap, epi_plot_heatmap_triangle, rcorr.

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
vars_list <- c('x', 'y', 'z')
var_labels <- c('numeric', 'binomial', 'poisson')
renamed_triangles <- epi_stats_corr_rename(melted_triangles$cormat_melted_triangle_r,
                                           melted_triangles$cormat_melted_triangle_pval,
                                           vars_list = vars_list,
                                           var_labels = var_labels
                                           )
renamed_triangles

## End(Not run)

AntonioJBT/episcout documentation built on Dec. 1, 2024, 4:07 a.m.