Joint predictive distribution of a fitted model
predict_distribution.RdDraws the response for every row of newdata jointly: each simulation
draws the coefficients from their (posterior) normal approximation,
shared by all rows, then each row's response from the family. Rows are
keyed row = 0, 1, .... An elastic_net_model has no standard errors,
so its draws hold the coefficients fixed (process uncertainty only) and
take a lambda from its path.
Arguments
- object
A glm_model, elastic_net_model, gam_model or bayes_glm_model (posterior predictive draws).
- newdata
A data frame with the model's terms.
- n_sims
Number of simulations.
- seed
Generator seed.
- ...
Unused; for methods.
- offset
Optional offset added to any
offset()terms.- weights
Optional prior weights.
- parameters
For a glm_model, how the coefficients are drawn:
"normal"(beta ~ N(beta_hat, Sigma); through a log link the draws' mean ismu_hat * exp(x' Sigma x / 2)),"mean_preserving"(the same, with each row's linear predictor shifted so its draws average the fitted mean exactly; log or identity link) or"fixed"(process uncertainty only).
Examples
d <- data.frame(y = c(2, 3, 5, 4, 6, 8), x = 1:6)
m <- glm_fit(y ~ x, d, family = "poisson")
pd <- predict_distribution(m, data.frame(x = c(7, 8)), n_sims = 1000, seed = 1)
mean(pd)
#> [1] 25.378