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: allocator's new scenario for ROAS target #648

Merged
merged 22 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3eac6af
feat: added scenario hit target roas
gufengzhou Mar 10, 2023
beb15bc
feat: adapted onepager for target roas
gufengzhou Mar 10, 2023
550c66d
feat: no need to define select_model when there's only one
laresbernardo Mar 10, 2023
4b8d6a3
docs update + simpler scenarios: max_response and target_roas
laresbernardo Mar 10, 2023
7b0df9b
feat: target cpa added into scenario
gufengzhou Mar 13, 2023
ffa7415
fix: update scenario for backwards compatibility
gufengzhou Mar 13, 2023
fd63dcb
docs: updates demo and params - 3.10.1 [dev]
laresbernardo Mar 13, 2023
9ce0321
fix: error when both CPA scenarios are same
gufengzhou Mar 14, 2023
00d781a
doc: update demo.R
gufengzhou Mar 14, 2023
d3a570b
fix: channel constraint NULL error
gufengzhou Mar 15, 2023
34d8b7d
recode: finetune plot labels
gufengzhou Mar 16, 2023
9a600c2
fix: pass export parameter correctly on allocator
laresbernardo Mar 17, 2023
49113a4
recode: finetune onepager & default target_value_ext
gufengzhou Mar 20, 2023
90f24cb
fix: NaN values set as 0
laresbernardo Mar 21, 2023
b748204
site: yarn upgrade
laresbernardo Mar 21, 2023
8288d26
docs: get rid of metric_ds => date_range
laresbernardo Mar 21, 2023
67cf946
recode: styler applied
laresbernardo Mar 21, 2023
8b76ee8
docs: export str_to_title and case_when
laresbernardo Mar 22, 2023
60780cc
recode: update demo.R
gufengzhou Mar 22, 2023
fd8d7ad
doc: remove old and redundant guide
gufengzhou Mar 22, 2023
b9eb87e
docs: fixed % escape + decomp_plot()
laresbernardo Mar 22, 2023
c8d87c1
Merge branch 'hit_roas_target' of https://github.com/facebookexperime…
laresbernardo Mar 22, 2023
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
6 changes: 3 additions & 3 deletions R/R/allocator.R
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ robyn_allocator <- function(robyn_object = NULL,
} else if (scenario == "target_efficiency") {
if (dep_var_type == "revenue") {
levs1 <- c(
"Initial", paste0("Hit ROAS x", round(target_value, 2)),
paste0("Hit ROAS x", target_value_ext)
"Initial", paste0("Hit ROAS $", round(target_value, 2)),
paste0("Hit ROAS $", target_value_ext)
)
} else {
levs1 <- c(
"Initial", paste0("Hit CPA $", round(target_value, 2)),
paste0("Hit CPA $", target_value_ext)
paste0("Hit CPA $", round(target_value_ext, 2))
)
}
}
Expand Down
23 changes: 16 additions & 7 deletions R/R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ allocation_plots <- function(InputCollect, OutputCollect, dt_optimOut, select_mo
pivot_longer(cols = !"type") %>%
left_join(resp_metric, "type") %>%
mutate(
name = factor(.data$name, levels = c("spend", "response")),
name = factor(paste("total", .data$name), levels = c("total spend", "total response")),
name_label = factor(
paste(.data$type, .data$name, sep = "\n"),
levels = paste(.data$type, .data$name, sep = "\n")
Expand All @@ -750,7 +750,7 @@ allocation_plots <- function(InputCollect, OutputCollect, dt_optimOut, select_mo
df_roi$labs <- factor(rep(labs, each = 2), levels = labs)

outputs[["p1"]] <- p1 <- df_roi %>%
ggplot(aes(x = .data$name_label, y = .data$value, fill = .data$type)) +
ggplot(aes(x = .data$name, y = .data$value, fill = .data$type)) +
facet_grid(. ~ .data$labs, scales = "free") +
scale_fill_manual(values = c("grey", "steelblue", "darkgoldenrod4")) +
geom_bar(stat = "identity", width = 0.6, alpha = 0.7) +
Expand Down Expand Up @@ -862,24 +862,33 @@ allocation_plots <- function(InputCollect, OutputCollect, dt_optimOut, select_mo
values = round(.data$values, 4),
# Deal with extreme cases divided by almost 0
values = ifelse((.data$values > 1e15 & .data$metric %in% c("ROAS", "mROAS")), 0, .data$values),
values_label = dplyr::case_when(
values_label = suppressWarnings(dplyr::case_when(
laresbernardo marked this conversation as resolved.
Show resolved Hide resolved
.data$metric %in% c("ROAS", "mROAS") ~ paste0("x", round(.data$values, 2)),
.data$metric %in% c("CPA", "mCPA") ~ formatNum(.data$values, 2, abbr = TRUE, pre = "$"),
TRUE ~ paste0(round(100 * .data$values, 1), "%")
),
)),
# Better fill scale colours
values_label = ifelse(grepl("NA|NaN", .data$values_label), "-", .data$values_label),
values = ifelse((is.nan(.data$values) | is.na(.data$values)), 0, .data$values)
values = ifelse((is.nan(.data$values) | is.na(.data$values)), 0, .data$values),
) %>%
mutate(
channel = factor(.data$channel, levels = rev(unique(.data$channel))),
metric = factor(
dplyr::case_when(
.data$metric %in% c("spend", "response") ~ paste0(.data$metric, "%"),
TRUE ~ .data$metric
),
levels = paste0(unique(.data$metric), c("%", "%", "", ""))
)
) %>%
mutate(channel = factor(.data$channel, levels = rev(unique(.data$channel)))) %>%
group_by(.data$name_label) %>%
mutate(
values_norm = lares::normalize(.data$values),
values_norm = ifelse(is.nan(.data$values_norm), 0, .data$values_norm)
)

outputs[["p2"]] <- p2 <- df_plot_share %>%
ggplot(aes(x = .data$name_label, y = .data$channel, fill = .data$type)) +
ggplot(aes(x = .data$metric, y = .data$channel, fill = .data$type)) +
geom_tile(aes(alpha = .data$values_norm), color = "white") +
scale_fill_manual(values = c("grey50", "steelblue", "darkgoldenrod4")) +
scale_alpha_continuous(range = c(0.6, 1)) +
Expand Down