Skip to content

Commit

Permalink
Calculate optimal media budget.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-s-zhang committed Jun 6, 2017
1 parent 53b067b commit 22a09af
Show file tree
Hide file tree
Showing 21 changed files with 771 additions and 128 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2017-05-15: Google <[email protected]>
* Version 1.0.0
* Initial commit.
2017-06-06: Google <[email protected]>
* Version 1.0.1
* New feature: ground truth for optimal media budget.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: amss
Version: 1.0.0
Date: 2017-05-15
Version: 1.0.1
Date: 2017-06-06
Title: Agreggate Marketing System Simulator
Author: Google Inc. <[email protected]>
Maintainer: Google Inc. <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(DefaultNatMigModule)
export(DefaultSalesModule)
export(DefaultSearchMediaModule)
export(DefaultTraditionalMediaModule)
export(OptimizeSpend)
export(SimulateAMSS)
export(SimulateAR1)
export(SimulateCorrelated)
Expand Down
16 changes: 9 additions & 7 deletions R/module_sales.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ utils::globalVariables(c(
#' columns corresponding to specific variables
#' @param price numeric vector of product price over time. If the vector is
#' shorter than the number of timepoints, it is repeated as necessary.
#' @param mean.price numeric scaler, the mean of price over time. Defaults to
#' zero.
#' @param advertiser.demand.intercept list of numeric vectors corresponding to
#' each brand state (favorability, loyalty, and availability). The
#' product of multiplicands corresponding to a particular segment with
#' 'purchase' activity state is the probability consumers in that
#' segment will purchase the advertiser's product if the price is 0 and
#' there is no competition. Missing members of the list have no effect
#' on the calculation.
#' segment will purchase the advertiser's product if the price is
#' mean.price and there is no competition. Missing members of the list have no
#' effect on the calculation.
#' @param advertiser.demand.slope list of numeric vectors corresponding to each
#' brand state (favorability, loyalty, and availability). The product of
#' multiplicands corresponding to a particular segment with 'purchase'
Expand Down Expand Up @@ -60,7 +62,7 @@ utils::globalVariables(c(
#' have no effect on the calculation.
#' @param purchase.quantity.intercept numeric, at least 1. Represents the
#' average number of units bought by each consumer purchasing from the
#' advertiser's brand.
#' advertiser's brand, if price is mean.price.
#' @param purchase.quantity.slope numeric, generally >= 0. Represents the
#' decrease in the average purchase quantity per consumer purchasing
#' from the advertiser's brand given a unit increase in price. Missing
Expand All @@ -86,7 +88,7 @@ utils::globalVariables(c(
#' @export

DefaultSalesModule <- function(
data.dt, price,
data.dt, price, mean.price = 0,
advertiser.demand.intercept = list(),
advertiser.demand.slope = list(
favorability = rep(0, length(kFavorabilityStates))),
Expand Down Expand Up @@ -148,7 +150,7 @@ DefaultSalesModule <- function(
1,
pmax(0,
advertiser.demand.intercept -
advertiser.demand.slope * current.price))
advertiser.demand.slope * (current.price - mean.price)))

# Add competition, and calculate final probabilities of consumers
# purchasing from the advertiser vs. competitor brands.
Expand Down Expand Up @@ -180,7 +182,7 @@ DefaultSalesModule <- function(
advertiser.units.per.purchaser <- max(
1,
purchase.quantity.intercept -
purchase.quantity.slope * current.price)
purchase.quantity.slope * (current.price - mean.price))
competitor.units.per.purchaser <- max(1, purchase.quantity.competitor)
# Simulate the total number of sales.
data.dt[,
Expand Down
Loading

0 comments on commit 22a09af

Please sign in to comment.