estim_counterfactual: Calculate counterfactual

Description Usage Arguments Details Value Examples

View source: R/counterfactual_f.R

Description

Simulate counterfactual scenarios.

Usage

1
2
3
4
estim_counterfactual(data,
                           model,
                           period,
                           alpha)

Arguments

data_input

The data containing the variables in the model, and a named column date with date time data. If no dates column is provided, then the first row is assumed to be a date.

selecte_model

A model for which scenarios are simulated

chosen_period

The period when the counterfactual scenario is simulated. The period covered by data_input should cover the chosen_period.

alpha

Optionally, the lag effect between (0,1). If it is not specified, it is set to zero.

Details

Most scenarios are constructed with historical actuals

Value

Return counterfactual values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Calculate counterfactual scenarios under different scenarios
data("sales_data")
sales_model1 <- lm(total ~
wday +
  month +
  adj_med_spend,
data = sales_data %>%
  filter(date < as.Date("2018-07-01"))
)

start_campaign <- as.Date("2018-07-01")
end_campaign <- as.Date("2018-07-25")
chosen_period <- start_campaign + seq(0, end_campaign - start_campaign)

## Scenario with no Media Spend
sales_data %>%
  mutate(adj_med_spend = min(adj_med_spend)) %>%
  estim_counterfactual(sales_model1, chosen_period) %>%
  sum()

## Sales under the scenario that we haven't done any marketing campaign
sales_data %>%
  estim_counterfactual(sales_model1, chosen_period) %>%
  sum()

monkeypostulate/MarketingAnalyticsR documentation built on Feb. 9, 2020, 12:15 a.m.