
Predict from a Mixed-Effects Cross-Price Demand Model
Source:R/cp-methods.R
predict.cp_model_lmer.RdGenerates predictions from a mixed-effects cross-price demand model (of class
cp_model_lmer). The function supports two modes:
Arguments
- object
A
cp_model_lmerobject (as returned byfit_cp_linear(type = "mixed", ...)).- newdata
A data frame containing at least an
xcolumn. Forpred_type = "random", anidcolumn is required. If absent, the function extracts unique ids fromobject$dataand expands the grid accordingly. If no ids are available, a default id of 1 is used (with a warning).- pred_type
Character string specifying the type of prediction: either
"fixed"(population-level) or"random"(subject-specific). The default is"fixed".- ...
Additional arguments passed to the underlying
predictfunction.
Value
A data frame containing all columns of newdata plus a column y_pred
with the corresponding predictions.
Details
"fixed"Returns predictions based solely on the fixed-effects component (using
re.form = NA)."random"Returns subject-specific predictions (fixed plus random effects) (using
re.form = NULL).
Examples
# \donttest{
data(etm)
fit <- fit_cp_linear(etm, type = "mixed")
new_prices <- data.frame(x = c(2, 4, 8, 16, 32, 64))
predict(fit, newdata = new_prices, pred_type = "fixed")
#> x y_pred
#> 1 2 2.951724
#> 2 4 3.065139
#> 3 8 3.291969
#> 4 16 3.745629
#> 5 32 4.652950
#> 6 64 6.467591
# }