plot.cp_model_lm: Plot Method for Linear Cross-Price Demand Models

plot.cp_model_lmR Documentation

Plot Method for Linear Cross-Price Demand Models

Description

Creates a ggplot2 visualization of a fitted linear cross-price demand model (of class cp_model_lm). The plot overlays a prediction line over the observed data points. Axis transformations (e.g., "log10") can be applied. If the model includes group effects, separate lines will be drawn for each group.

Usage

## S3 method for class 'cp_model_lm'
plot(
  x,
  data = NULL,
  x_trans = "identity",
  y_trans = "identity",
  n_points = 100,
  xlab = "Price",
  ylab = "Consumption",
  title = NULL,
  point_size = 3,
  ...
)

Arguments

x

A cp_model_lm object (as returned by fit_cp_linear(type = "fixed", ...)).

data

Optional data frame containing columns x and y to plot. If not provided, the function uses object$data if available.

x_trans

Transformation for the x-axis; one of "identity", "log10", or "pseudo_log". Default is "identity".

y_trans

Transformation for the y-axis; one of "identity", "log10", or "pseudo_log". Default is "identity".

n_points

Number of points to create in the prediction grid. Default is 100.

xlab

Label for the x-axis. Default is "Price".

ylab

Label for the y-axis. Default is "Consumption".

title

Optional title for the plot; default is NULL.

point_size

Size of the data points in the plot. Default is 3.

...

Additional arguments passed to the generic predict method.

Value

A ggplot2 object displaying the fitted model predictions and observed data.


bkaplan4/beezdemand documentation built on June 11, 2025, 2:36 a.m.