Skip to content

Commit

Permalink
fix: remove negative carryover output for weibull_pdf #706
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
gufengzhou committed May 15, 2023
1 parent dad1cfa commit cf104bb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/R/response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf104bb

Please sign in to comment.