From cf104bb01fdcdd5744f447c45a7b54eb3f04a767 Mon Sep 17 00:00:00 2001 From: gufengzhou Date: Mon, 15 May 2023 15:56:08 +0800 Subject: [PATCH] fix: remove negative carryover output for weibull_pdf #706 - weibull_pdf creates lagged peak and thus negative carryover, because the previous carryover = total - raw, and with lagged peaks, total adstocked spend might be lower than raw spend. The new calculation doesn't take raw spend as immediate anymore, but derives immediate from the actual lagged decay matrix. This restores the relationship of total = carryover + immediate with all positive values. - This is the 3rd code snippets change (robyn_response) that impacts the csv output. Other other two in transformation.R and allocator.R were fixed previously. Will look into funtionalizing the 3 places. --- R/R/response.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/R/response.R b/R/R/response.R index 5b4ccf7b9..88c7db19f 100644 --- a/R/R/response.R +++ b/R/R/response.R @@ -178,10 +178,10 @@ robyn_response <- function(InputCollect = NULL, if (usecase == "all_historical_vec") { ds_list <- check_metric_dates(date_range = "all", all_dates, dayInterval, quiet, ...) - val_list <- check_metric_value(metric_value, metric_name, all_values, ds_list$metric_loc) + #val_list <- check_metric_value(metric_value, metric_name, all_values, ds_list$metric_loc) } else if (usecase == "unit_metric_default_last_n") { ds_list <- check_metric_dates(date_range = paste0("last_", length(metric_value)), all_dates, dayInterval, quiet, ...) - val_list <- check_metric_value(metric_value, metric_name, all_values, ds_list$metric_loc) + #val_list <- check_metric_value(metric_value, metric_name, all_values, ds_list$metric_loc) } else { ds_list <- check_metric_dates(date_range, all_dates, dayInterval, quiet, ...) } @@ -243,7 +243,9 @@ robyn_response <- function(InputCollect = NULL, ## Adstocking simulation x_list_sim <- transform_adstock(all_values_updated, adstock, theta = theta, shape = shape, scale = scale) media_vec_sim <- x_list_sim$x_decayed + media_vec_sim_imme <- if (adstock == "weibull_pdf") x_list_sim$x_imme else x_list_sim$x input_total <- media_vec_sim[ds_list$metric_loc] + input_immediate <- media_vec_sim_imme[ds_list$metric_loc] input_carryover <- input_total - input_immediate ## Saturation