knitr::opts_chunk$set( echo = TRUE, collapse = TRUE, comment = "#>", dev = "png", dpi = 144, fig.width = 7, fig.height = 5, warning = FALSE, message = FALSE ) library(beezdemand) library(dplyr)
Starting with beezdemand version 0.2.0, FitCurves() has been superseded by
fit_demand_fixed(). This guide helps you migrate existing code to use the
modern API.
For related workflows, see:
vignette("beezdemand") for getting startedvignette("model-selection") for choosing a model classvignette("mixed-demand") and vignette("mixed-demand-advanced") for mixed-effects modelsvignette("hurdle-demand-models") for hurdle modelsThe new fit_demand_fixed() function provides:
summary(), tidy(),
glance(), predict(), plot(), confint(), augment())tidy() and glance()FitCurves() will continue to work but is no longer actively developed.
New features will only be added to fit_demand_fixed().
| FitCurves() | fit_demand_fixed() | Notes |
|-------------|---------------------|-------|
| dat | data | Renamed for consistency |
| xcol | x_var | Renamed for consistency |
| ycol | y_var | Renamed for consistency |
| idcol | id_var | Renamed for consistency |
| detailed = TRUE | Always detailed | fit_demand_fixed always returns full results |
| groupcol | Not supported | Use factor models instead |
| Returns data.frame | Returns S3 object | Use tidy() for data frame output |
# Old approach results <- FitCurves( dat = apt, equation = "hs", k = 2, xcol = "x", ycol = "y", idcol = "id" ) # results is a data.frame with all parameters head(results)
# New approach fit <- fit_demand_fixed( data = apt, equation = "hs", k = 2, x_var = "x", y_var = "y", id_var = "id" ) # fit is a structured S3 object print(fit)
# FitCurves returns a data frame directly results <- FitCurves(apt, "hs", k = 2) q0_values <- results$Q0d alpha_values <- results$Alpha
# Use tidy() for a tibble of coefficients fit <- fit_demand_fixed(apt, equation = "hs", k = 2) coefs <- tidy(fit) head(coefs) # Or access the results data frame directly head(fit$results)
# Manual calculation required results <- FitCurves(apt, "hs", k = 2) n_converged <- sum(!is.na(results$Alpha)) mean_r2 <- mean(results$R2, na.rm = TRUE)
# Use glance() for model-level statistics fit <- fit_demand_fixed(apt, equation = "hs", k = 2) glance(fit) # Or use summary() for comprehensive output summary(fit)
# Required detailed = TRUE and manual extraction results <- FitCurves(apt, "hs", k = 2, detailed = TRUE) # Predictions stored in list element predictions <- results$newdats # List of data frames
# Use predict() method fit <- fit_demand_fixed(apt, equation = "hs", k = 2) # Predict at new prices new_prices <- data.frame(x = c(0, 0.5, 1, 2, 5, 10)) preds <- predict(fit, newdata = new_prices) head(preds)
# Used separate PlotCurves() function results <- FitCurves(apt, "hs", k = 2, detailed = TRUE) PlotCurves(results)
# Use plot() method directly on the fit object fit <- fit_demand_fixed(apt, equation = "hs", k = 2) # Plot first 5 subjects plot(fit, ids = unique(apt$id)[1:5], facet = TRUE)
Once you migrate to the modern API, you can use standardized post-fit helpers:
augment() to get fitted values + residuals in a tidy formatcheck_demand_model() for a structured diagnostic summaryplot_residuals() for common residual diagnostics (via augment())fit <- fit_demand_fixed(apt, equation = "hs", k = 2) augment(fit) |> head() check_demand_model(fit) plot_residuals(fit)$fitted
For user-facing workflows, prefer:
check_systematic_demand() (purchase task)check_systematic_cp() (cross-price)These wrap legacy helpers (e.g., CheckUnsystematic()) but return a standardized
beezdemand_systematicity object.
sys <- check_systematic_demand(apt) head(sys$results)
Both functions support aggregation, with identical syntax:
# Fit to mean data fit_mean <- fit_demand_fixed(apt, equation = "hs", k = 2, agg = "Mean") tidy(fit_mean)
Both functions support log10 parameterization:
# Fit in log10 space fit_log <- fit_demand_fixed( apt, equation = "hs", k = 2, param_space = "log10" ) # tidy() can report in either scale tidy(fit_log, report_space = "log10") |> head() tidy(fit_log, report_space = "natural") |> head()
| Feature | FitCurves() | fit_demand_fixed() |
|---------|-------------|---------------------|
| Equations | hs, koff, linear | hs, koff, linear |
| k options | numeric, "ind", "fit", "share" | numeric, "ind", "fit", "share" |
| Aggregation | "Mean", "Pooled" | "Mean", "Pooled" |
| Parameter space | natural, log10 | natural, log10 |
| summary() method | No | Yes |
| tidy() method | No | Yes |
| glance() method | No | Yes |
| predict() method | No | Yes |
| plot() method | No | Yes |
| coef() method | No | Yes |
| augment() method | No | Yes |
| confint() method | No | Yes |
If you need to continue using FitCurves() without warnings (e.g., in legacy
code or during a gradual migration), you can suppress the deprecation message:
# Suppress deprecation warning temporarily rlang::with_options( lifecycle_verbosity = "quiet", FitCurves(apt, "hs", k = 2) )
However, we strongly recommend migrating to fit_demand_fixed() for new code.
If you encounter issues during migration:
?fit_demand_fixedvignette("beezdemand") -- Getting started with beezdemandvignette("model-selection") -- Choosing the right model classvignette("fixed-demand") -- Fixed-effect demand modelingvignette("mixed-demand") -- Mixed-effects nonlinear demand modelsvignette("mixed-demand-advanced") -- Advanced mixed-effects topicsvignette("hurdle-demand-models") -- Two-part hurdle demand modelsvignette("cross-price-models") -- Cross-price demand analysisvignette("group-comparisons") -- Group comparisonssessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.