Skip to content

Commit 5df9fe5

Browse files
committed
feat: frequency bucket
- update reach & frequency dataset to include the frequency bucket as dimension - update robyn_calibrate to account for freq_bucket loop - add beta coef to nevergrad hyperparameter to improve curve fit - new r&f plot with freq_bucket - adapted default loss_min_step_rel to 0.0001 to account for larger loss values now due to coef - update documentation - add df_curve_reach_freq as dummy dataset
1 parent 8092ff6 commit 5df9fe5

File tree

8 files changed

+509
-311
lines changed

8 files changed

+509
-311
lines changed

R/R/calibration.R

Lines changed: 408 additions & 287 deletions
Large diffs are not rendered by default.

R/R/data.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,45 @@
6161
# lares::missingness(dt_prophet_holidays)
6262
# dt_prophet_holidays <- dplyr::filter(dt_prophet_holidays, !is.na(country))
6363
# save(dt_prophet_holidays, file = "data/dt_prophet_holidays.RData", version = 2)
64+
65+
####################################################################
66+
#' Robyn Dataset: Reach & frequency simulated dataset
67+
#'
68+
#' A simulated cumulated reach and spend dataset by frequency buckets.
69+
#' The headers must be kept as
70+
#' \code{c("spend_cumulated", "response_cumulated", "freq_bucket")}.
71+
#'
72+
#'
73+
#' @family Dataset
74+
#' @docType data
75+
#' @usage data(df_curve_reach_freq)
76+
#' @return data.frame
77+
#' @format An object of class \code{"data.frame"}
78+
#' \describe{
79+
#' \item{spend_cumulated}{cumulated spend of paid media}
80+
#' \item{response_cumulated}{cumulated reach of paid media}
81+
#' \item{freq_bucket}{Frequency bucket for cumulated reach}
82+
#' }
83+
#' @examples
84+
#' data(df_curve_reach_freq)
85+
#' head(df_curve_reach_freq)
86+
#' @return Dataframe.
87+
"df_curve_reach_freq"
88+
89+
# xSample <- round(seq(0, 100000, length.out = 10))
90+
# gammaSamp <- seq(0.3, 1, length.out = 20)
91+
# coeff <- 10000000
92+
# df_curve_reach_freq <- list()
93+
# for (i in seq_along(gammaSamp)) {
94+
# df_curve_reach_freq[[i]] <- data.frame(
95+
# spend_cumulated = xSample,
96+
# response_predicted = (xSample**0.5 / (xSample**0.5 + (gammaSamp[i] * max(xSample))**0.5)) * coeff ,
97+
# gamma = gammaSamp[i],
98+
# freq_bucket = as.factor(paste0("reach ", i, "+"))
99+
# )
100+
# }
101+
# df_curve_reach_freq <- bind_rows(df_curve_reach_freq) %>%
102+
# mutate(response_cumulated = response_predicted * (1+ runif(length(xSample) * length(gammaSamp), -0.05, 0.05))) %>%
103+
# select(spend_cumulated, response_cumulated, response_predicted, freq_bucket)
104+
# levels(df_curve_reach_freq$freq_bucket) <- paste0("reach ", seq_along(gammaSamp), "+")
105+
# save(df_curve_reach_freq, file = "data/df_curve_reach_freq.RData", version = 2)

R/R/plots.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,8 @@ allocation_plots <- function(
824824
.data$value / dplyr::first(.data$value)
825825
})
826826
metric_vals <- if (metric == "ROAS") resp_metric$total_roi else resp_metric$total_cpa
827-
resp_delta <- df_roi %>% group_by(type) %>%
828-
summarise(resp_delta = unique(total_response_lift)) %>%
827+
resp_delta <- df_roi %>% group_by(.data$type) %>%
828+
summarise(resp_delta = unique(.data$total_response_lift)) %>%
829829
pull(resp_delta)
830830
labs <- paste(
831831
paste(levs2, "\n"),

R/data/df_curve_reach_freq.RData

2.62 KB
Binary file not shown.

R/man/df_curve_reach_freq.Rd

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

R/man/dt_prophet_holidays.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

R/man/dt_simulated_weekly.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

R/man/robyn_calibrate.Rd

Lines changed: 17 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)