Simplify R Squared calculations

This commit is contained in:
2024-09-16 12:27:24 -04:00
parent 22236fef49
commit 4f90330500

View File

@@ -1231,6 +1231,7 @@ main <- function() {
generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots",
plot_configs = rank_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
message("Generating ranked linear model plots")
# Generate rank plots for L and K using linear model (`lm`) ranks
rank_lm_plot_configs <- generate_rank_plot_configs(
df = zscores_interactions,
@@ -1243,7 +1244,7 @@ main <- function() {
generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots_lm",
plot_configs = rank_lm_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
message("Filtering and regenerating rank plots")
message("Filtering and reranking plots")
# Filter rows where either Z_lm_L or Avg_Zscore_L is not NA
# Formerly X_NArm
zscores_interactions_filtered <- zscores_interactions %>%
@@ -1252,10 +1253,10 @@ main <- function() {
ungroup() %>%
rowwise() %>%
mutate(
lm_R_squared_L = if (n() > 1) summary(lm(Z_lm_L ~ Avg_Zscore_L))$r.squared else NA,
lm_R_squared_K = if (n() > 1) summary(lm(Z_lm_K ~ Avg_Zscore_K))$r.squared else NA,
lm_R_squared_r = if (n() > 1) summary(lm(Z_lm_r ~ Avg_Zscore_r))$r.squared else NA,
lm_R_squared_AUC = if (n() > 1) summary(lm(Z_lm_AUC ~ Avg_Zscore_AUC))$r.squared else NA,
lm_R_squared_L = summary(lm(Z_lm_L ~ Avg_Zscore_L))$r.squared,
lm_R_squared_K = summary(lm(Z_lm_K ~ Avg_Zscore_K))$r.squared,
lm_R_squared_r = summary(lm(Z_lm_r ~ Avg_Zscore_r))$r.squared,
lm_R_squared_AUC = summary(lm(Z_lm_AUC ~ Avg_Zscore_AUC))$r.squared,
Overlap = case_when(
Z_lm_L >= 2 & Avg_Zscore_L >= 2 ~ "Deletion Enhancer Both",
@@ -1269,23 +1270,24 @@ main <- function() {
) %>%
ungroup()
message("Generating filtered rank plots")
message("Generating filtered ranked plots")
rank_plot_filtered_configs <- generate_rank_plot_configs(
df = zscores_interactions_filtered,
interaction_vars = interaction_vars,
is_lm = FALSE,
adjust = FALSE
)$plot_configs
)
generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots_na_rm",
plot_configs = rank_plot_filtered_configs,
grid_layout = list(ncol = 3, nrow = 2))
message("Generating filtered ranked linear model plots")
rank_plot_lm_filtered_configs <- generate_rank_plot_configs(
df = zscores_interactions_filtered,
interaction_vars = interaction_vars,
is_lm = TRUE,
adjust = FALSE
)$plot_configs
)
generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots_lm_na_rm",
plot_configs = rank_plot_lm_filtered_configs,
grid_layout = list(ncol = 3, nrow = 2))