Post Estimation utilities
Welfare and revenue calculations
An important use case for structural search models is to compute revenue and consumer welfare effects of different models.
The following functions provide this functionality.
StructuralSearchModels.calculate_welfare — Function
calculate_welfare(model::Model, data::Data, n_sim; kwargs...)Calculate consumer welfare for model using data and n_sim simulation draws. Requires that calculate_costs! has been called on model beforehand.
Returns
A Dict with three top-level keys: :average, :conditional_on_search, and :conditional_on_purchase. Each contains a nested Dict with keys :welfare, :utility, :search_costs, and :discovery_costs, which are all averages across sessions in the respective group.
Example
# First compute costs
calculate_costs!(m_hat, d, 100_000; seed = 1)
W = calculate_welfare(m_hat, d, 1000; seed = 1)
W[:average][:welfare] # average welfare across all sessions
W[:conditional_on_purchase][:welfare] # welfare for sessions with a purchaseStructuralSearchModels.calculate_revenues — Function
calculate_revenues(model::Model, data::Data, kprice, n_draws; kwargs...)Calculate revenues for model using data and n_draws simulation draws. kprice is the column index in the product characteristics matrix used as the price attribute.
Returns
A Dict with keys:
:revenues:Float64— total revenues summed across all sessions:demand:Float64— total demand summed across all sessions:revenues_individual:Vector{Float64}— revenues per session:demand_individual:Vector{Float64}— demand per session
Example
R = calculate_revenues(m_hat, d, 1, 50; seed = 1)
R[:revenues] # total revenues
R[:demand] # total demandModel fit evaluation
To evaluate model fit, the following function can be used to compare moments in the data with those implied by the model.
StructuralSearchModels.calculate_fit_measures — Function
calculate_fit_measures(model::Model, data::Data, n_sim; kwargs...)Compute fit measures of model for data using n_sim simulation draws. kwargs are passed to the data generation function.
Returns
A Dict with keys :click_stats_data, :click_stats_sim, :purchase_stats_data, :purchase_stats_sim, :stop_probabilities_data, :stop_probabilities_sim, and :bounds. The _data keys contain the empirical moments; the _sim keys contain the corresponding simulated moments.
Example
fit_measures = calculate_fit_measures(m_hat, d, 1000; seed = 1)
# Compare position-specific click probabilities
prob_sim = fit_measures[:click_stats_sim][:click_probability_per_position]
prob_data = fit_measures[:click_stats_data][:click_probability_per_position]
hcat(prob_sim, prob_data)