| residuals.brma | R Documentation |
Computes residuals (observed minus fitted values) from a fitted brma object, with options for standardization.
## S3 method for class 'brma'
residuals(
object,
type = "outcome",
unit = "estimate",
conditioning_depth = "marginal",
bias_adjusted = FALSE,
...
)
object |
a fitted brma object |
type |
the type of residuals to compute. Options are:
|
unit |
output unit. Only |
conditioning_depth |
conditioning depth for non-LOO residuals. |
bias_adjusted |
whether residuals should be computed from bias-adjusted
fitted values. Defaults to |
... |
additional arguments. |
Raw residuals (type = "outcome") are computed as:
e_i = y_i - \hat{\mu}_i
where y_i is the observed effect size and \hat{\mu}_i is the
fitted value (prediction from the fixed effects).
Pearson residuals (type = "pearson") divide raw residuals by the
marginal standard error:
r_i^{Pearson} = \frac{e_i}{\sqrt{v_i + \tau^2}}
where v_i is the sampling variance and \tau^2 is the
relevant heterogeneity component. Only available for normal outcome models
without selection (weightfunction) bias adjustment.
Standardized residuals (type = "rstandard") use the hat matrix to
compute residual standard errors that account for the uncertainty in
estimated coefficients:
z_i = \frac{e_i}{\sqrt{[(I-H)M(I-H)']_{ii}}}
where H is the hat matrix and M is the marginal variance-covariance
matrix. For models without moderators, this simplifies to the Pearson formula.
Only available for normal outcome models without selection (weightfunction)
bias adjustment.
LOO-PIT residuals (type = "LOO-PIT") are the Bayesian equivalent of
studentized deleted residuals \insertCitevehtari2017practicalRoBMA. They
are computed via leave-one-out probability integral transformation:
r_i = \Phi^{-1}(u_i)
where u_i = \sum_s w_{is} F(y_i | \theta^{(s)}) is the LOO-weighted CDF
value, w_{is} are the normalized PSIS weights, and F is the
cumulative distribution function of the estimate-unit predictive
distribution used by LOO. Under a correctly specified model, LOO-PIT
residuals should follow a standard normal distribution. Unlike traditional
standardized residuals, LOO-PIT residuals properly account for estimation
uncertainty and leverage without requiring a hat matrix. This is the
recommended method for standardized residuals in Bayesian meta-analysis.
For meta-regression models, fitted values incorporate moderator effects. For models without moderators, all fitted values equal the pooled effect.
For GLMM models (binomial or Poisson), observed effect sizes and their
sampling variances are computed from the raw frequency data using the
same formulas as metafor::escalc with the default zero-cell
adjustment (adding 0.5 to all cells when any cell is zero). GLMM residuals
and LOO-PIT values are therefore approximate effect-size-scale diagnostics,
not exact PIT diagnostics for the raw count likelihood.
The residuals are computed separately for each posterior sample, naturally propagating uncertainty in model parameters to the residuals.
A numeric vector of residual means, one per estimate.
predict.brma(), blup.brma(), pooled_effect(), rstandard.brma(), rstudent.brma()
## Not run:
if (requireNamespace("metadat", quietly = TRUE)) {
data(dat.lehmann2018, package = "metadat")
fit <- bPET(
yi = yi,
vi = vi,
data = dat.lehmann2018,
measure = "SMD",
seed = 1,
silent = TRUE
)
# raw residuals (default)
residuals(fit)
# Pearson and internally standardized residuals
residuals(fit, type = "pearson")
residuals(fit, type = "rstandard")
# LOO-PIT residuals require stored LOO
fit <- add_loo(fit)
residuals(fit, type = "LOO-PIT")
# residuals from bias-adjusted predictions
residuals(fit, bias_adjusted = TRUE)
# check Pareto k diagnostics
plot(loo(fit))
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.