
Compute Z-residuals for hurdle or count Poisson brms models
Source:R/Zresidual.hurdle.poisson.brms.R
Zresidual_hurdle_poisson_brms.RdComputes Z-residuals for fitted Bayesian hurdle or count models
with a Poisson distribution using a brms model with
family = hurdle_poisson(). Z-residuals can be calculated for
zeros, counts, or the overall hurdle distribution, and can be used
for model diagnostics.
This is an internal workhorse for Zresidual.hurdle_poisson.brms()
and is not intended to be called directly by end users.
Arguments
- fit
A fitted brms model object for a hurdle or count Poisson outcome.
- type
Character string specifying which part of the model to calculate Z-residuals for:
"zero"for the hurdle/zero portion,"count"for the truncated Poisson counts,"hurdle"for the full hurdle-Poisson model.- method
Character string specifying the residual calculation method:
"iscv"for importance-sampled cross-validated randomized predictive p-values,"rpost"for randomized posterior predictive p-values, or"mpost"for middle-value posterior predictive p-values. Default is"iscv".- n.rep
Integer; the number of replicated Z-residual sets to generate. Default is
1.
Value
A numeric matrix of Z-residuals with attributes such as:
type: The requested model component.zero_id: Indices of zero outcomes.log_pmf: Log-probability mass function values.log_cdf: Log-cumulative distribution function values.covariates: Model covariates.linear.pred: Linear predictor values from the fitted model.
The S3 wrapper Zresidual.hurdle_poisson.brms() will additionally
attach the class "zresid" to the returned object.
Details
A typical implementation:
Extracts the observed response vector from the model data.
Computes the log-PMF and log-CDF for the specified part of the model using the corresponding
log_pred_dist_*function, such aslog_pred_dist_HPorlog_pred_dist_TP.Generates posterior predictive p-values according to the specified
method.Converts the p-values to Z-residuals via the negative quantile of the standard normal distribution.
The output is a matrix of Z-residuals with one column per replication.
See also
log_pred_dist_HP, log_pred_dist_TP,
post_logrpp, iscv_logrpp,
and the S3 wrapper Zresidual.hurdle_poisson.brms().