View source: R/hurdle-methods.R
| augment.beezdemand_hurdle | R Documentation |
Returns the original data with fitted values, residuals, and predictions from a hurdle demand model. This enables easy model diagnostics and visualization with the tidyverse.
## S3 method for class 'beezdemand_hurdle'
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). |
For two-part hurdle models:
.fitted gives predicted demand on the natural consumption scale
.fitted_prob gives the predicted probability of positive consumption
.resid is defined only for positive observations as log(y) - .fitted_link
Observations with zero consumption have .resid = NA since they are
explained by Part I (the zero-probability component), not Part II
A tibble containing the original data plus:
Fitted demand values (natural scale)
Fitted values on log scale (Part II mean)
Predicted probability of consumption (1 - P(zero))
Residuals on log scale for positive observations, NA for zeros
Residuals on response scale (y - .fitted)
data(apt)
fit <- fit_demand_hurdle(apt, y_var = "y", x_var = "x", id_var = "id")
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.