From b24463fa831dd4add2b012304e1d148b7f329bca Mon Sep 17 00:00:00 2001 From: Bryan Roessler Date: Sat, 5 Oct 2024 22:57:25 -0400 Subject: [PATCH] Summarize linear model coefficeints for correlation plots --- .../apps/r/calculate_interaction_zscores.R | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R index 31e5027d..afd76114 100644 --- a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R +++ b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R @@ -416,6 +416,18 @@ calculate_interaction_scores <- function(df, df_bg, type, overlap_threshold = 2) R_Squared_r = first(R_Squared_r), R_Squared_AUC = first(R_Squared_AUC), + # lm intercepts + lm_intercept_L = first(lm_intercept_L), + lm_intercept_K = first(lm_intercept_K), + lm_intercept_r = first(lm_intercept_r), + lm_intercept_AUC = first(lm_intercept_AUC), + + # lm slopes + lm_slope_L = first(lm_slope_L), + lm_slope_K = first(lm_slope_K), + lm_slope_r = first(lm_slope_r), + lm_slope_AUC = first(lm_slope_AUC), + # NG, DB, SM values NG = first(NG), DB = first(DB), @@ -439,7 +451,7 @@ calculate_interaction_scores <- function(df, df_bg, type, overlap_threshold = 2) TRUE ~ "No Effect" ), - # For correlations + # For correlation plots lm_R_squared_L = if (!all(is.na(Z_lm_L)) && !all(is.na(Avg_Zscore_L))) summary(lm(Z_lm_L ~ Avg_Zscore_L))$r.squared else NA, lm_R_squared_K = if (!all(is.na(Z_lm_K)) && !all(is.na(Avg_Zscore_K))) summary(lm(Z_lm_K ~ Avg_Zscore_K))$r.squared else NA, lm_R_squared_r = if (!all(is.na(Z_lm_r)) && !all(is.na(Avg_Zscore_r))) summary(lm(Z_lm_r ~ Avg_Zscore_r))$r.squared else NA, @@ -1208,12 +1220,11 @@ generate_correlation_plot_configs <- function(df) { x_var <- paste0("Z_lm_", rel$x) y_var <- paste0("Z_lm_", rel$y) - # Access the correlation statistics from the correlation_stats list + # Extract the R-squared, intercept, and slope from the df relationship_name <- paste0(rel$x, "_vs_", rel$y) # Example: L_vs_K - stats <- correlation_stats[[relationship_name]] - intercept <- stats$intercept - slope <- stats$slope - r_squared <- stats$r_squared + intercept <- mean(df[[paste0("lm_intercept_", rel$x)]], na.rm = TRUE) + slope <- mean(df[[paste0("lm_slope_", rel$x)]], na.rm = TRUE) + r_squared <- mean(df[[paste0("lm_R_squared_", rel$x)]], na.rm = TRUE) # Generate the label for the plot plot_label <- paste("Interaction", rel$x, "vs.", rel$y)