qqnorm.brma creates a normal QQ plot for a fitted brma
object. The plot displays sorted standardized residuals on the vertical axis
against the theoretical quantiles of a standard normal distribution on the
horizontal axis. Under a correctly specified model, the points should fall
approximately along the diagonal reference line.
# S3 method for brma
qqnorm(
y,
type = "rstudent",
unit = "estimate",
conditioning_depth = "marginal",
envelope = TRUE,
conf_level = 95,
bonferroni = FALSE,
reps = 1000,
smooth = TRUE,
xlim,
ylim,
xlab,
ylab,
plot_type = "base",
...
)For plot_type = "base", returns an invisible list with
components x (theoretical quantiles) and y (sorted
residuals). For plot_type = "ggplot", returns a ggplot object.
If as_data = TRUE, returns a list with all computed plot data
including: x, y, points, refline,
envelope, xlim, ylim, xlab, and ylab.
a fitted brma object.
the type of standardized residuals to use. Options are:
"rstudent" (alias: "LOO-PIT"; default): Leave-one-out
probability integral transform residuals. Works for all model types
including GLMMs and selection models. This is the recommended type for
Bayesian models as it properly accounts for estimation uncertainty and
leverage. Note: requires that loo has been computed (see
add_loo).
"rstandard": Internally standardized residuals using the hat
matrix. Only available for normal outcome models without selection
(weightfunction) bias adjustment.
output unit. Only "estimate" is implemented currently.
residual conditioning depth. Options are
"marginal", "cluster", and "estimate".
logical indicating whether to add a pseudo confidence
envelope to the plot. The envelope is created by simulating sets of
standard normal quantiles, providing a reference for the expected variability
under a correctly specified model. Defaults to TRUE.
numeric value between 0 and 100 specifying the confidence level
for the envelope bounds. Defaults to 95.
logical indicating whether to apply Bonferroni correction
to the envelope, so it can be regarded as a simultaneous confidence region
for all \(k\) residuals. Defaults to FALSE.
retained for compatibility with earlier simulation-based envelopes. The current envelope is deterministic and does not use this argument.
logical indicating whether to smooth the envelope bounds using
Friedman's SuperSmoother (supsmu). Defaults to
TRUE.
x-axis limits. If not specified, limits are computed from data.
y-axis limits. If not specified, limits are computed from data.
title for the x-axis. If not specified, defaults to
"Theoretical Quantiles".
title for the y-axis. If not specified, defaults to
"Sample Quantiles".
whether to use a base plot "base" or ggplot2
"ggplot" for plotting. Defaults to "base".
additional graphical arguments to customize the plot appearance:
point symbol (default: 21, filled circle)
point border color (default: "black")
point fill/background color (default: "#A6A6A6")
point size multiplier for base graphics (default: 1)
point size for ggplot2 (default: 2)
fill color for the envelope region (default: "grey90").
Set to NA to suppress shading.
color for envelope boundary lines (default: "grey50")
color of the diagonal reference line (default: "black")
character string for plot title (default: no title)
if TRUE, returns plot data instead of creating
the plot
The normal QQ plot is a diagnostic tool for assessing whether the standardized residuals follow a standard normal distribution, as expected under a correctly specified model. Each point represents one estimate, plotted at coordinates \((\Phi^{-1}(p_i), z_{(i)})\) where \(p_i\) are the plotting positions and \(z_{(i)}\) are the sorted standardized residuals.
The default residual type is "rstudent" (LOO-PIT), which differs
from metafor::qqnorm (which defaults to "rstandard").
LOO-PIT residuals are preferred because they are available for all model
types (including GLMMs and selection models) and properly account for
estimation uncertainty via leave-one-out cross-validation.
The confidence envelope is computed in closed form from the distribution of
normal order statistics. For the \(i\)-th sorted residual,
\(\Phi(Z_{(i)})\) follows a beta distribution with shape parameters
\(i\) and \(k + 1 - i\). Pointwise quantile bounds are transformed back
with \(\Phi^{-1}\). When smooth = TRUE, bounds are smoothed using
Friedman's SuperSmoother. When bonferroni = TRUE, the confidence
level is adjusted for simultaneous inference across all \(k\) comparisons.
For GLMM models, LOO-PIT residuals and the QQ plot are computed on the
approximate effect-size scale used by loo; they are not exact
count-scale PIT diagnostics.
rstudent.brma(), rstandard.brma(), residuals.brma(),
funnel.brma(), radial.brma()
if (FALSE) {
if (requireNamespace("metadat", quietly = TRUE)) {
data(dat.lehmann2018, package = "metadat")
fit <- brma(
yi = yi,
vi = vi,
data = dat.lehmann2018,
measure = "SMD",
seed = 1,
silent = TRUE
)
fit <- add_loo(fit)
qqnorm(fit)
qqnorm(fit, type = "rstandard")
qqnorm(fit, envelope = FALSE)
qqnorm(fit, plot_type = "ggplot")
qqnorm(fit, pch = 19, col = "blue", shade = "lightblue")
}
}
Run the code above in your browser using DataLab