fit_demand_fixed: Fit Fixed-Effect Demand Curves

View source: R/fixed-demand.R

fit_demand_fixedR Documentation

Fit Fixed-Effect Demand Curves

Description

Modern interface for fitting individual demand curves via nonlinear least squares. Returns a structured S3 object with standard methods including summary(), tidy(), and glance().

Usage

fit_demand_fixed(
  data,
  equation = c("hs", "koff", "simplified", "linear", "exponential", "exponentiated"),
  k = 2,
  agg = NULL,
  x_var = "x",
  y_var = "y",
  id_var = "id",
  param_space = c("natural", "log10"),
  ...
)

Arguments

data

Data frame in long format with columns: id, x (price), y (consumption).

equation

Character. Equation type: "hs" (Hursh & Silberberg, 2008), "koff" (Koffarnus et al., 2015), "simplified" (Rzeszutek et al., 2025; simplified exponential with normalized decay, no k parameter), or "linear". The modern aliases "exponential" (equivalent to "hs") and "exponentiated" (equivalent to "koff") are also accepted. Default "hs".

k

Scaling constant. Numeric value (fixed), "ind" (individual), "fit" (free parameter), or "range" (data-driven). Default 2.

agg

Character. Aggregation method: "Mean", "Pooled", or NULL for individual fits. Default NULL.

x_var

Character. Name of the price column. Default "x".

y_var

Character. Name of the consumption column. Default "y".

id_var

Character. Name of the subject identifier column. Default "id".

param_space

Character. Parameterization used for fitting. One of:

  • "natural": fit Q0, alpha (and k if k = "fit") on their natural scale

  • "log10": fit log10(Q0), log10(alpha) (and log10(k) if k = "fit")

...

Additional arguments passed to the underlying FitCurves() engine.

Details

This function is a modern wrapper around the legacy FitCurves() function. It provides the same fitting capabilities but returns a structured S3 object with standardized methods for model interrogation.

Value

An object of class beezdemand_fixed with components:

results

Data frame of fitted parameters for each subject

fits

List of model fit objects (if detailed = TRUE internally)

predictions

List of prediction data frames

data_used

List of data frames used for each fit

call

The original function call

equation

The equation form used

k_spec

Description of k specification

agg

Aggregation method used

n_total

Total number of subjects/fits attempted

n_success

Number of successful fits

n_fail

Number of failed fits

Examples


data(apt)
fit <- fit_demand_fixed(apt, equation = "hs", k = 2)
print(fit)
summary(fit)
tidy(fit)
glance(fit)



beezdemand documentation built on March 3, 2026, 9:07 a.m.