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
)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
Character: "hs", "koff", "hurdle", "hurdle_hs_stdq0", "snd", "simplified", or NULL
Named list of parameters. Names depend on model_type:
hs/koff: alpha, q0, k
hurdle: alpha, q0, k (note: hurdle uses different formula)
hurdle_hs_stdq0: alpha, q0, k (Q0 appears inside exponent)
snd/simplified: alpha, q0
Named list mapping parameter names to their input scales: "natural", "log", or "log10". Default assumes all natural.
Optional function E(p) for numerical fallback. If NULL and model_type is provided, will be constructed from params.
Optional function Q(p) for elasticity calculation.
Numeric vector of observed prices (required for observed metrics and domain constraints).
Numeric vector of observed consumption (for observed metrics).
Tolerance for unit elasticity check (default 0.1).
Logical; compute observed metrics? Default TRUE if price_obs and consumption_obs are provided.
# \donttest{
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
# }
Run the code above in your browser using DataLab