View source: R/pmax-omax-engine.R
| beezdemand_calc_pmax_omax | R Documentation |
Unified internal engine for pmax/omax computation. Supports analytic solutions (Lambert W for HS/hurdle, closed-form for SND), numerical fallback, and observed (row-wise) metrics. Handles parameter-space conversions transparently.
beezdemand_calc_pmax_omax(
model_type = NULL,
params = NULL,
param_scales = NULL,
expenditure_fn = NULL,
demand_fn = NULL,
price_obs = NULL,
consumption_obs = NULL,
tol = 0.1,
compute_observed = NULL
)
model_type |
Character: "hs", "koff", "hurdle", "hurdle_hs_stdq0", "snd", "simplified", or NULL |
params |
Named list of parameters. Names depend on model_type:
|
param_scales |
Named list mapping parameter names to their input scales: "natural", "log", or "log10". Default assumes all natural. |
expenditure_fn |
Optional function E(p) for numerical fallback. If NULL and model_type is provided, will be constructed from params. |
demand_fn |
Optional function Q(p) for elasticity calculation. |
price_obs |
Numeric vector of observed prices (required for observed metrics and domain constraints). |
consumption_obs |
Numeric vector of observed consumption (for observed metrics). |
tol |
Tolerance for unit elasticity check (default 0.1). |
compute_observed |
Logical; compute observed metrics? Default TRUE if price_obs and consumption_obs are provided. |
A list with snake_case fields:
Model-based pmax
Model-based omax
Quantity at pmax
Method used: "analytic_lambert_w", "analytic_snd", "numerical_optimize_observed_domain"
Price domain used for computation
Logical; is pmax at domain boundary?
Elasticity evaluated at pmax
Logical; is elasticity near -1?
Any notes about model computation
Observed pmax
Observed omax
Method for observed: "row_wise_max"
Tie-break rule: "min_price"
Number of observation rows
Number of unique prices
Logical; duplicate prices detected?
Number of rows achieving omax
Notes about observed computation
Input scale for alpha
Input scale for Q0
Input scale for k (if applicable)
Notes about parameter conversions
result <- beezdemand_calc_pmax_omax(
model_type = "hs",
params = list(alpha = 0.001, q0 = 10, k = 3),
price_obs = c(0, 0.5, 1, 2, 4, 8, 16),
consumption_obs = c(10, 9, 8, 6, 3, 1, 0)
)
result$pmax_model
result$omax_model
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.