| fit_demand_mixed | R Documentation |
Fits a nonlinear mixed-effects model for behavioral economic demand data. The function allows Q0 and alpha parameters to vary by specified factors and supports different demand equation forms.
fit_demand_mixed(
data,
y_var,
x_var,
id_var,
factors = NULL,
factor_interaction = FALSE,
equation_form = c("zben", "simplified", "exponentiated"),
param_space = c("log10", "natural"),
k = NULL,
custom_model_formula = NULL,
fixed_rhs = NULL,
continuous_covariates = NULL,
start_value_method = c("heuristic", "pooled_nls"),
random_effects = Q0 + alpha ~ 1,
covariance_structure = c("pdDiag", "pdSymm"),
start_values = NULL,
collapse_levels = NULL,
nlme_control = list(msMaxIter = 200, niterEM = 100, maxIter = 200, pnlsTol = 0.001,
tolerance = 1e-06, apVar = TRUE, minScale = 1e-09, opt = "nlminb", msVerbose = FALSE),
method = "ML",
...
)
data |
A data frame. |
y_var |
Character string, the name of the dependent variable column.
For |
x_var |
Character string, the name of the independent variable column (e.g., "x", price). |
id_var |
Character string, the name of the subject/group identifier column for random effects. |
factors |
A character vector of factor names (up to two) by which Q0 and alpha
are expected to vary (e.g., |
factor_interaction |
Logical. If |
equation_form |
Character string specifying the demand equation form. Options are:
|
param_space |
Character. Parameterization used for fitting core demand parameters. One of:
Notes:
|
k |
Numeric. Range parameter (in log10 units) used with |
custom_model_formula |
An optional custom nonlinear model formula (nlme format).
If provided, this overrides |
fixed_rhs |
Optional one-sided formula or character string specifying the
right-hand side (RHS) for the fixed-effects linear models of |
continuous_covariates |
Optional character vector of continuous (numeric)
predictor names to be included additively in the fixed-effects RHS when
|
start_value_method |
Character, method to generate starting values if |
random_effects |
A formula or a list of formulas for the random effects structure.
Default |
covariance_structure |
Character, covariance structure for random effects.
Options: |
start_values |
Optional named list of starting values for fixed effects.
If |
collapse_levels |
Optional named list specifying factor level collapsing separately for Q0 and alpha parameters. Structure: list( Q0 = list(factor_name = list(new_level = c(old_levels), ...)), alpha = list(factor_name = list(new_level = c(old_levels), ...)) ) Either |
nlme_control |
Control parameters for |
method |
Fitting method for |
... |
Additional arguments passed to |
An object of class beezdemand_nlme.
# Basic mixed-effects demand fit with apt data
# Transform consumption using LL4 for the zben equation
apt_ll4 <- apt |> dplyr::mutate(y_ll4 = ll4(y))
fit <- fit_demand_mixed(
data = apt_ll4,
y_var = "y_ll4",
x_var = "x",
id_var = "id",
equation_form = "zben"
)
print(fit)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.