Compute Z-residuals for a Bernoulli/Logistic brms model
Source:R/Zresidual.bernoulli.brms.R
Zresidual_bernoulli_brms.RdComputes Z-residuals for a fitted Bayesian Bernoulli/Logistic (binary)
model fitted with brms::brm() and family = bernoulli(). Z-residuals
are calculated using posterior predictive methods and can be used for
model diagnostics.
This is an internal workhorse for Zresidual.bernoulli.brms() and is
not intended to be called directly by end users.
Arguments
- fit
A fitted
brmsfitmodel object with Bernoulli family.- 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.- data
Optional data frame used to override the data stored inside
fitfor prediction and diagnostic calculation. IfNULL, the data embedded infitare used.- type
Optional character string controlling the residual type; the meaning is determined by the underlying implementation (if used).
- ...
Further arguments passed to lower-level helpers.
Value
A numeric matrix of Z-residuals with attributes:
type: Type of outcome (Bernoulli).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.
Details
The function typically performs the following steps:
Extracts the observed response vector from the model data.
Computes the log-PMF and log-CDF for the Bernoulli model using
log_pred_dist_bern.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_bern, post_logrpp,
iscv_logrpp,
and the S3 wrapper Zresidual.bernoulli.brms().