Fit the Forecasts Scenarios STAN Model
Create Forecast Model Inputs#'
Fit Forecast Model
Processes the draws for the Customer Model Forecasts
Processes the waterfall draws from Forecast Model
Usage
fit_forecast_model(
forecasts,
n_scenarios,
cpa_scenarios,
spend_scenarios,
config
)
forecast_stan_dat(
forecasts,
n_scenarios,
cpa_scenarios,
spend_scenarios,
config
)
forecast_fit_model(stan_dat)
forecast_process_draws(draws, n_scenarios)
forecast_waterfall_draws(draws, scenario)Arguments
- forecasts
Forecasts dataset generated from
fit_customer_model().- n_scenarios
Number of scenario's to test.
- cpa_scenarios
Numeric matrix. A set of
CPAscenarios the client wants to test.- spend_scenarios
Numeric matrix. A set of
spendscenarios the client wants to test.- config
Configuration list created by
appraise_configure().- stan_dat
List of STAN data inputs created by
forecast_stan_dat()- draws
A Draws object created by
fit$draws()- scenario
Numeric scenario to get the waterfall chart for.
Details
For each of the forecast periods in your configuration, we can
predict the associated transactions and sales. For the model to work,
please supply a matrix of CPA scenarios and a matrix of Spend scenarios
equal to the number of prediction periods (e.g., nrow(forecasts)). If you
have multiple scenarios, create them as separate columns and supply
n_scenarios = n
Examples
if (FALSE) { # \dontrun{
set.seed(123)
config <- appraise_configure(sample = TRUE,
cpa = c(25, 50, 75, 100, 125, 150, 200),
cm = c(.2, .3, .432, .5),
currency = '$',
n_forecast = 5)
forecasts <- customer_level_predictions$forecasts
# Generating sample CPA scenarios
cpa_scenarios <-
sample(c(25, 50, 75, 100, 125, 150, 200),
size = nrow(forecasts),
replace = TRUE) %>%
as.matrix()
# Generating sample Spend scenarios
spend_scenarios <-
sample(c(25000, 50000, 75000, 100000, 125000, 150000, 200000),
size = nrow(forecasts),
replace = TRUE) %>%
as.matrix()
#### Automated flow ----
scenario_predictions_automated <-
fit_forecast_model(forecasts,
n_scenarios = 1,
cpa_scenarios,
spend_scenarios,
config)
#### Individual flow ----
n_scenarios = 1
stan_dat <- forecast_stan_dat(forecasts,
n_scenarios = n_scenarios,
cpa_scenarios,
spend_scenarios,
config)
fit <- forecast_fit_model(stan_dat)
draws <- fit$draws()
forecasts <- forecast_process_draws(draws, n_scenarios = 1)
forecast_waterfalls <- 1:n_scenarios %>% lapply(forecast_waterfall_draws, draws = draws)
scenario_predictions_individual <- list()
scenario_predictions_individual[["stan_dat"]] <- stan_dat
scenario_predictions_individual[["fit"]] <- fit
scenario_predictions_individual[["draws"]] <- draws
scenario_predictions_individual[["forecasts"]] <- forecasts
scenario_predictions_individual[["forecast_waterfalls"]] <- forecast_waterfalls
identical(
scenario_predictions_automated$forecasts,
scenario_predictions_individual$forecasts
)
identical(
scenario_predictions_automated$forecast_waterfalls,
scenario_predictions_individual$forecast_waterfalls
)
} # }