Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RSSD penalty for 0 media effects media (parameter) #680

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions R/R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#' "unconstrained". By default, if intercept is negative, Robyn will drop intercept
#' and refit the model. Consider changing intercept_sign to "unconstrained" when
#' there are \code{context_vars} with large positive values.
#' @param rssd_zero_penalty Boolean. When TRUE, the objective function
#' DECOMP.RSSD will penalize models with more 0 media effects additionally.
#' In other words, given the same DECOMP.RSSD score, a model with 50% 0-coef
#' variables will get penalized by DECOMP.RSSD * 1.5 (larger error), while
#' another model with no 0-coef variables gets un-penalized with DECOMP.RSSD * 1.
#' @param seed Integer. For reproducible results when running nevergrad.
#' @param outputs Boolean. Process results with \code{robyn_outputs()}?
#' @param lambda_control Deprecated in v3.6.0.
Expand Down Expand Up @@ -73,6 +78,7 @@ robyn_run <- function(InputCollect = NULL,
cores = NULL,
trials = 5,
iterations = 2000,
rssd_zero_penalty = TRUE,
nevergrad_algo = "TwoPointsDE",
intercept_sign = "non_negative",
lambda_control = NULL,
Expand Down Expand Up @@ -149,6 +155,7 @@ robyn_run <- function(InputCollect = NULL,
dt_hyper_fixed = dt_hyper_fixed,
ts_validation = ts_validation,
add_penalty_factor = add_penalty_factor,
rssd_zero_penalty = rssd_zero_penalty,
refresh, seed, quiet
)

Expand Down Expand Up @@ -276,6 +283,7 @@ robyn_train <- function(InputCollect, hyper_collect,
dt_hyper_fixed = NULL,
ts_validation = TRUE,
add_penalty_factor = FALSE,
rssd_zero_penalty = TRUE,
refresh = FALSE, seed = 123,
quiet = FALSE) {
hyper_fixed <- hyper_collect$all_fixed
Expand All @@ -291,6 +299,8 @@ robyn_train <- function(InputCollect, hyper_collect,
intercept_sign = intercept_sign,
dt_hyper_fixed = dt_hyper_fixed,
ts_validation = ts_validation,
add_penalty_factor = add_penalty_factor,
rssd_zero_penalty = rssd_zero_penalty,
seed = seed,
quiet = quiet
)
Expand Down Expand Up @@ -325,6 +335,7 @@ robyn_train <- function(InputCollect, hyper_collect,
intercept_sign = intercept_sign,
ts_validation = ts_validation,
add_penalty_factor = add_penalty_factor,
rssd_zero_penalty = rssd_zero_penalty,
refresh = refresh,
trial = ngt,
seed = seed + ngt,
Expand Down Expand Up @@ -382,6 +393,7 @@ robyn_mmm <- function(InputCollect,
add_penalty_factor = FALSE,
dt_hyper_fixed = NULL,
# lambda_fixed = NULL,
rssd_zero_penalty = TRUE,
refresh = FALSE,
trial = 1L,
seed = 123L,
Expand Down Expand Up @@ -449,6 +461,7 @@ robyn_mmm <- function(InputCollect,
add_penalty_factor <- add_penalty_factor
intercept_sign <- intercept_sign
i <- NULL # For parallel iterations (globalVar)
rssd_zero_penalty <- rssd_zero_penalty
}

################################################
Expand Down Expand Up @@ -788,6 +801,12 @@ robyn_mmm <- function(InputCollect,
)
if (!refresh) {
decomp.rssd <- sqrt(sum((dt_decompSpendDist$effect_share - dt_decompSpendDist$spend_share)^2))
# Penalty for models with more 0-coefficients
if (rssd_zero_penalty) {
is_0eff <- round(dt_decompSpendDist$effect_share, 4) == 0
share_0eff <- sum(is_0eff) / length(dt_decompSpendDist$effect_share)
decomp.rssd <- decomp.rssd * (1 + share_0eff)
}
} else {
dt_decompRF <- select(decompCollect$xDecompAgg, .data$rn, decomp_perc = .data$xDecompPerc) %>%
left_join(select(xDecompAggPrev, .data$rn, decomp_perc_prev = .data$xDecompPerc),
Expand Down
2 changes: 1 addition & 1 deletion R/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Robyn: Continuous & Semi-Automated MMM <img src='man/figures/logo.png' align="right" height="139px" />
### The Open Source Marketing Mix Model Package from Meta Marketing Science

[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/Robyn)](https://cran.r-project.org/package=Robyn) [![website](https://img.shields.io/badge/site-Robyn-blue.svg)](https://facebookexperimental.github.io/Robyn/) [![facebook](https://img.shields.io/badge/group-Facebook-blue.svg)](https://www.facebook.com/groups/robynmmm/)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/Robyn)](https://cran.r-project.org/package=Robyn) [![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/Robyn?color=green)](https://cran.r-project.org/web/packages/Robyn/index.html) [![website](https://img.shields.io/badge/site-Robyn-blue.svg)](https://facebookexperimental.github.io/Robyn/) [![facebook](https://img.shields.io/badge/group-Facebook-blue.svg)](https://www.facebook.com/groups/robynmmm/)
---

Project Robyn aims to radically change Marketing Mix Modelling (MMM) practice by utilizing automation, ground-truth calibration, and incorporating AI in an open-source approach. While demystifying the use of these techniques, Robyn helps to reduce and minimize human bias in MMM, ensuring that the results are based on objective and validated statistical analysis. The AI algorithms & ground-truth calibration used in Robyn aim to minimize the potential for subjective interpretations and decision making. This leads to a more accurate representation of the impact of marketing investments, enabling organizations of all sizes to make impartial data-driven decisions. Project Robyn, along with strong community support, represents a step towards the future of MMM, where the use of AI and automation will become the norm, providing unbiased and reliable results every time. By creating an open-source platform, Project Robyn is democratizing access to underlying technology, enabling organizations of all sizes to benefit from unbiased MMM analysis either as final end-users or agencies & consultancies building their own businesses upon Robyn. The data science, the code, and various business case studies are available for everyone to learn from and use.
Expand Down
7 changes: 7 additions & 0 deletions R/man/robyn_mmm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions R/man/robyn_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions R/man/robyn_train.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.