This helper function creates demand curves

ec_demcurve(
  ec_long,
  focal_product,
  rel_pricerange,
  dem_fun,
  draws,
  epsilon_not = NULL
)

Arguments

ec_long

choice scenario (discrete or volumetric)

focal_product

Logical vector picking the focal product for which to create a demand curve

rel_pricerange

Price range, relative to base case price; this is used to create demand curve

dem_fun

demand function (e.g., dd_prob for HMNL or vd_dem_vdm for volumetric demand). For discrete choice, use choice probabilities instead of choice predictions.

draws

ec-draws object (e.g., output from dd_est_hmnl or vd_est_vd)

epsilon_not

(optional) error realisatins (this helps make curves look smother for voumetric models)

Value

List containing aggregate demand quantities for each scenario defined by rel_pricerange

See also

ec_gen_err_normal() to generate error realization from Normal distribution, ec_gen_err_ev1() to generate error realization from EV1 distribution

Examples

# \donttest{
data(icecream)
#run MCMC sampler (use way more than 50 draws for actual use)
icecream_est <- icecream %>% dplyr::filter(id<100) %>% 
vd_est_vdm(R=20, keep=1)
#> Using 16 cores
#>  MCMC in progress 
#> MCMC complete
#>  Total Time Elapsed: 0.00 minutes
#demand at different price points
dem_scenarios<-
ec_demcurve(icecream%>% dplyr::filter(id<100),
 icecream%>% dplyr::filter(id<100) %>% pull('Brand')=="Store",
 c(.75,1,1.25),vd_dem_vdm,icecream_est)
#> Using 16 cores
#> Using 16 cores
#> Using 16 cores
#optional plot
# dem_scenarios %>% 
#   do.call('rbind',.) %>%
#   ggplot(aes(x=scenario,y=`E(demand)`,color=Flavor)) + geom_line()
# }