Skip to content

Commit

Permalink
fix: media var selection error #1191
Browse files Browse the repository at this point in the history
- minor fix and tested on local machine with different robyn_inputs specs, e.g. paid_media_spends and paid_media_vars are identical, or paid_media_spends only while paid_media_vars = NULL. All work as expected.
- bump up version
  • Loading branch information
gufengzhou committed Jan 21, 2025
1 parent 597fb1a commit 03752e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Robyn
Type: Package
Title: Semi-Automated Marketing Mix Modeling (MMM) from Meta Marketing Science
Version: 3.12.0.9004
Version: 3.12.0.9005
Authors@R: c(
person("Gufeng", "Zhou", , "[email protected]", c("cre", "aut")),
person("Igor", "Skokan", , "[email protected]", c("aut")),
Expand Down
24 changes: 16 additions & 8 deletions R/R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,13 @@ robyn_mmm <- function(InputCollect,
mean_spend = unlist(summarise_all(temp, mean))
) %>%
mutate(spend_share = .data$total_spend / sum(.data$total_spend))
temp <- select(dt_inputTrain, all_of(c(exposure_vars, organic_vars))) %>% summarise_all(mean) %>% unlist
temp <- data.frame(rn = c(exposure_vars, organic_vars), mean_exposure = temp)
dt_spendShare <- full_join(dt_spendShare, temp, by = "rn")
if (length(c(exposure_vars, organic_vars)) > 0) {
temp <- select(dt_inputTrain, all_of(c(exposure_vars, organic_vars))) %>% summarise_all(mean) %>% unlist
temp <- data.frame(rn = c(exposure_vars, organic_vars), mean_exposure = temp)
dt_spendShare <- full_join(dt_spendShare, temp, by = "rn")
} else {
dt_spendShare$mean_exposure <- NA
}
# When not refreshing, dt_spendShareRF = dt_spendShare
refreshAddedStartWhich <- which(dt_modRollWind$ds == refreshAddedStart)
temp <- select(dt_inputTrain, all_of(paid_media_spends)) %>%
Expand All @@ -562,11 +566,15 @@ robyn_mmm <- function(InputCollect,
) %>%
mutate(spend_share = .data$total_spend / sum(.data$total_spend))
# Join both dataframes into a single one
temp <- select(dt_inputTrain, all_of(c(exposure_vars, organic_vars))) %>%
slice(refreshAddedStartWhich:rollingWindowLength) %>%
summarise_all(mean) %>% unlist
temp <- data.frame(rn = c(exposure_vars, organic_vars), mean_exposure = temp)
dt_spendShareRF <- full_join(dt_spendShareRF, temp, by = "rn")
if (length(c(exposure_vars, organic_vars)) > 0) {
temp <- select(dt_inputTrain, all_of(c(exposure_vars, organic_vars))) %>%
slice(refreshAddedStartWhich:rollingWindowLength) %>%
summarise_all(mean) %>% unlist
temp <- data.frame(rn = c(exposure_vars, organic_vars), mean_exposure = temp)
dt_spendShareRF <- full_join(dt_spendShareRF, temp, by = "rn")
} else {
dt_spendShareRF$mean_exposure <- NA
}
dt_spendShare <- left_join(dt_spendShare, dt_spendShareRF, "rn", suffix = c("", "_refresh"))


Expand Down

0 comments on commit 03752e9

Please sign in to comment.