View source: R/mixed-methods.R
| augment.beezdemand_nlme | R Documentation |
Returns the original data with fitted values and residuals from a nonlinear mixed-effects demand model. This enables easy model diagnostics and visualization with the tidyverse.
## S3 method for class 'beezdemand_nlme'
augment(x, newdata = NULL, ...)
x |
An object of class |
newdata |
Optional data frame of new data for prediction. If NULL, uses the original data from the model. |
... |
Additional arguments (currently unused). |
The fitted values and residuals are on the same scale as the response variable
used in the model. For equation_form = "zben", this is the LL4-transformed
scale. For equation_form = "simplified" or "exponentiated", this is the natural
consumption scale.
To back-transform predictions to the natural scale for "zben" models, use:
ll4_inv(augmented$.fitted)
A tibble containing the original data plus:
Fitted values on the model scale (may be transformed, e.g., LL4)
Residuals on the model scale
Fitted values from fixed effects only (population-level)
data(ko)
fit <- fit_demand_mixed(ko, y_var = "y_ll4", x_var = "x",
id_var = "monkey", factors = "dose", equation_form = "zben")
augmented <- augment(fit)
# Plot residuals
library(ggplot2)
ggplot(augmented, aes(x = .fitted, y = .resid)) +
geom_point(alpha = 0.5) +
geom_hline(yintercept = 0, linetype = "dashed")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.