| er_style_model | R Documentation |
Builder functions for the model layer (er_plot_add_model()), drawing
the fitted exposure-response curve as a ribbon-and-line, a line alone, or a
spaghetti plot of simulated draws.
er_style_model_ribbonline(
data,
config,
stratify,
exposure,
response,
strata,
theme,
ribbon_fill = "grey40",
ribbon_alpha = 0.25,
ribbon_edges = FALSE,
linewidth = 1,
...
)
er_style_model_line(
data,
config,
stratify,
exposure,
response,
strata,
theme,
linewidth = 1,
...
)
er_style_model_spaghetti(
data,
config,
stratify,
exposure,
response,
strata,
theme,
alpha = NULL,
linewidth = 1,
nsim = 100L,
...
)
data |
The original data frame |
config |
Configuration for the specific plot |
stratify |
Logical indicating whether to stratify |
exposure |
Exposure variable |
response |
Response variable |
strata |
Stratification variable |
theme |
Theme components |
ribbon_fill |
Fill colour for |
ribbon_alpha |
Transparency of |
ribbon_edges |
Whether |
linewidth |
Width of the fitted curve's line, for all three
model builders ( |
... |
Additional named arguments forwarded from
|
alpha |
Transparency of |
nsim |
Number of simulated draws for |
See er_style() for the shared builder interface these functions
implement, including how to write a custom builder of your own.
A geom, or a list of geoms; see er_style().
All three builders draw the same fitted exposure-response curve; which one to reach for is a choice of how to convey uncertainty around it:
er_style_model_ribbonline() (the default) – the curve plus a
shaded confidence ribbon.
er_style_model_line() – the curve alone, omitting the ribbon.
er_style_model_spaghetti() – the curve overlaid on individual
simulated draws instead of a ribbon, for models that implement
er_simulate().
All three are tagged er_style_tag(fn, layer = "plot_model"), so
er_plot_add_model() errors informatively if handed one of these
tagged for a different layer entirely (e.g. "summary", meant for
er_plot_add_summary()). Each also carries a registered short-string
label – "ribbonline"/"line"/"spaghetti" respectively – so
er_plot_add_model()'s style argument can take that string instead
of the function itself (see er_style_labels()).
er_style()
if (requireNamespace("erglm", quietly = TRUE)) {
library(erglm)
mod <- erglm_model(ae1 ~ aucss, erglm_data, family = binomial())
# er_style_model_ribbonline(): ribbon + line, the default
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(mod, style = er_style_model_ribbonline) |>
plot()
# er_style_model_line(): line only, no ribbon
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(mod, style = er_style_model_line) |>
plot()
# er_style_model_spaghetti(): simulated draws instead of a ribbon;
# `seed` is forwarded to `er_simulate()` via `...`
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(mod, style = er_style_model_spaghetti, seed = 4821) |>
plot()
# overriding a builder's own visual defaults: a thicker, less
# saturated ribbon with its bounds outlined, and fewer/fainter
# spaghetti draws
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(
mod,
style = er_style_model_ribbonline,
ribbon_fill = "steelblue",
ribbon_alpha = 0.15,
ribbon_edges = TRUE,
linewidth = 1.5
) |>
plot()
erglm_data |>
er_plot(aucss, ae1) |>
er_plot_add_model(
mod,
style = er_style_model_spaghetti,
seed = 4821,
nsim = 40L,
alpha = 0.05
) |>
plot()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.