Summarize linear model coefficeints for correlation plots

This commit is contained in:
2024-10-05 22:57:25 -04:00
parent f335b414e1
commit b24463fa83

View File

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