Creates a ggplot2 visualization of a fitted mixed-effects cross-price demand model
(of class cp_model_lmer). This function allows you to plot:
# S3 method for cp_model_lmer
plot(
x,
data = NULL,
inv_fun = identity,
n_points = 100,
title = NULL,
xlab = "Price",
ylab = "Consumption",
x_trans = "identity",
y_trans = "identity",
point_size = 3,
pred_type = c("fixed", "random", "all"),
...
)A ggplot2 object displaying the observed data points along with the prediction curves.
A cp_model_lmer object (as returned by
fit_cp_linear(type = "mixed", ...)).
Optional data frame containing columns x and y to be plotted.
If not provided, object$data is used.
Optional function to inverse-transform predictions. Default is identity.
Not typically used for linear models but included for API consistency.
Number of points to use in creating the prediction grid. Default is 100.
Optional title for the plot; default is NULL.
Label for the x-axis. Default is "Price".
Label for the y-axis. Default is "Consumption".
Transformation for the x-axis; one of "identity", "log10", or
"pseudo_log". Default is "identity".
Transformation for the y-axis; one of "identity", "log10", or
"pseudo_log". Default is "identity".
Size of the observed data points. Default is 3.
Character string specifying which prediction components to plot:
"fixed"Plot only the fixed-effects (population) prediction.
"random"Plot only the subject-specific predictions.
"all"Plot both the fixed-effects and the subject-specific predictions.
The default is "fixed".
Additional arguments passed to predict.cp_model_lmer.
"fixed"Only the population-level (fixed-effects) prediction.
"random"Only the subject-specific predictions.
"all"Both: the fixed-effects and the subject-specific predictions.
If the model includes group effects, separate lines will be drawn for each group.