| er_vpc | R Documentation |
Create an er_vpc specification for a visual predictive check.
Build the plot by adding an observed layer and a simulated layer,
and render with plot()/print() or er_vpc_build().
er_vpc(
data,
exposure,
response,
stratify_by = NULL,
response_type = "auto",
plot_by = NULL,
n_bins = 4,
ties = "upward",
quantile_type = 7,
labeller = NULL,
conf_level = 0.95,
probs = c(0.1, 0.5, 0.9),
seed = NULL
)
data |
Data frame or tibble containing the observed data. |
exposure |
Exposure variable (one variable, unquoted). |
response |
Response variable (one variable, unquoted). |
stratify_by |
Optional variable (unquoted) splitting the VPC into
one facet panel per level, via |
response_type |
One of |
plot_by |
Variable (unquoted) plotted on the x-axis and used to
bin/group the observed vs. simulated comparison. Defaults to
|
n_bins |
Number of quantile bins, when |
ties, quantile_type, labeller |
Control how a numeric |
conf_level |
Confidence level for both the observed- and
simulated-side intervals. Must be strictly between 0 and 1.
Defaults to |
probs |
Percentiles to compute for a percentile-based builder
(e.g. |
seed |
Optional single number seeding the observed layer's random
tie-break when |
er_vpc_add_observed() bins the observed data and computes its
response summary; er_vpc_add_simulated() must be added afterwards,
since it reuses the observed layer's own binning decision so both
sides share identical bin boundaries. Both layers are singletons (a
second call replaces the previous one).
er_vpc()'s own stratification (stratify_by) is real, but simpler
than er_plot()'s: a facet-only split via ggplot2::facet_wrap(),
with no colour/facet precedence rule to reconcile (see stratify_by
below). It's orthogonal to plot_by – see er_vpc_add_observed()
for plot_by, the variable plotted on the x-axis and used to
bin/group the comparison. Whether plot_by is "continuous"
(numeric, quantile-binned) or "discrete" (used as-is) is
auto-detected from the column's type and stored on
object$group$type, mirroring how object$response$type records
the response's type.
An (empty) plot object of class er_vpc.
er_vpc_add_observed(), er_vpc_add_simulated(),
er_vpc_build(), er_model_interface
if (requireNamespace("erglm", quietly = TRUE)) {
library(erglm)
mod <- erglm_model(ae2 ~ aucss + sex, erglm_data, family = binomial())
erglm_data |>
er_vpc(aucss, ae2, plot_by = aucss) |>
er_vpc_add_observed() |>
er_vpc_add_simulated(model = mod, seed = 9984) |>
plot()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.