From d9a251c717cb793126b822413002e7e4173d4357 Mon Sep 17 00:00:00 2001 From: Matt Dancho Date: Sun, 29 Oct 2023 11:01:35 -0400 Subject: [PATCH] fix clean calculation --- R/00_global_vars.R | 2 +- R/anomalize-plotting.R | 6 +++--- R/anomalize.R | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/00_global_vars.R b/R/00_global_vars.R index c46fc9ae..1cc5b2cf 100644 --- a/R/00_global_vars.R +++ b/R/00_global_vars.R @@ -10,5 +10,5 @@ globalVariables( ".metric", ".metrics", ".rank_metric", ".rank_std_err", "failure_rate", "std_err", ".rank_failure_rate", ".txt", "training", "testing", "fitted", "model", "..val", "..nm", ".white_noise_lower", ".white_noise_upper", ".date_var_collapsed", ".rowid", "..date_agg", "grp_names", - "check_row_exists", ".box_group", ".observed_cleaned") + "check_row_exists", ".box_group", ".observed_clean") ) diff --git a/R/anomalize-plotting.R b/R/anomalize-plotting.R index b0dfe899..354849d9 100644 --- a/R/anomalize-plotting.R +++ b/R/anomalize-plotting.R @@ -713,7 +713,7 @@ plot_anomalies_cleaned <- function( } column_names <- names(.data) - check_names <- c("observed", "observed_cleaned") %in% column_names + check_names <- c("observed", "observed_clean") %in% column_names if (!all(check_names)) stop('Error in plot_anomalies_decomp(): column names are missing. Run `anomalize()` and make sure: observed, remainder, anomaly, recomposed_l1, and recomposed_l2 are present', call. = FALSE) UseMethod("plot_anomalies_cleaned", .data) @@ -821,10 +821,10 @@ plot_anomalies_cleaned.data.frame <- function( g <- g + ggplot2::scale_color_manual(values = c(.line_color, .cleaned_line_color)) - # Add line - observed_cleaned + # Add line - observed_clean g <- g + ggplot2::geom_line( - ggplot2::aes(y = observed_cleaned, color = "Observed Cleaned"), + ggplot2::aes(y = observed_clean, color = "Observed Cleaned"), # color = .cleaned_line_color, linewidth = .cleaned_line_size, linetype = .cleaned_line_type, diff --git a/R/anomalize.R b/R/anomalize.R index aea3c029..469dc06b 100644 --- a/R/anomalize.R +++ b/R/anomalize.R @@ -190,9 +190,9 @@ anomalize.data.frame <- function( # Clean ret <- ret %>% dplyr::mutate( - observed_cleaned = dplyr::case_when( - anomaly_direction == -1 ~ .clean_alpha * recomposed_l1, - anomaly_direction == 1 ~ .clean_alpha * recomposed_l2, + observed_clean = dplyr::case_when( + anomaly_direction == -1 ~ recomposed_l1 + (1-.clean_alpha)*anomaly_score, + anomaly_direction == 1 ~ recomposed_l2 - (1-.clean_alpha)*anomaly_score, TRUE ~ observed ) )