View source: R/moplot_onepred.R
| moplot_onepred | R Documentation |
moplot_onepred() creates a graphical representation of the contrasts
associated with one categorical predictor in a fitted model.
The upper panel displays the quantities compared by each contrast, together with their confidence intervals. The optional lower panel displays the corresponding model parameter, its confidence interval, and an approximate Cohen's d.
The horizontal position of each parameter in the lower panel is inherited from the midpoint of the corresponding contrast in the upper panel.
moplot_onepred(
model,
predictor,
data = NULL,
sig_level = 0.05,
conf_level = 0.95,
estimate_type = c("auto", "observed", "predicted"),
prediction_scale = c("response", "link"),
coefficient_scale = c("model", "interpreted"),
per_difference = FALSE,
bounds = NULL,
hypotheses = NULL,
show_coef = TRUE,
show_data = FALSE,
style = c("minimal", "publication"),
caption = TRUE,
digits = 2L,
base_size = 13,
panel_heights = c(2, 1)
)
model |
A fitted model supported by the package. |
predictor |
A single character string identifying the categorical predictor to display. |
data |
Optional data frame containing the variables used to fit
|
sig_level |
A numeric value between 0 and 1 defining the significance
threshold used for the contrast labels. The default is |
conf_level |
A numeric value between 0 and 1 specifying the confidence
level. The default is |
estimate_type |
Character string specifying how the quantities in the upper panel should be computed. Available options are:
|
prediction_scale |
Character string specifying the scale used for
model-based predictions. Available options are |
coefficient_scale |
Character string specifying the estimate displayed in the lower panel. Available options are:
|
per_difference |
Logical. Should the lower-panel coefficients be
divided by their scale factor? The default is For some codings, such as Helmert and reverse Helmert contrasts or
custom matrices, each model coefficient equals a scale factor |
bounds |
Optional numeric vector |
hypotheses |
Optional numeric matrix declaring the comparisons that
the coefficients of |
show_coef |
Logical. Should the lower coefficient panel be displayed?
The default is |
show_data |
Logical. Should raw observations be displayed in the upper
panel using horizontal jittering? The default is |
style |
Character string specifying the graphical style. Available options are:
|
caption |
Controls whether a descriptive caption is printed in the console. It can be:
The caption is not added to the graphical object. Each sentence is printed on a separate console line so that the text can be copied and used independently of the plot. |
digits |
Number of decimal places used in the lower-panel labels.
The default is |
base_size |
Base font size used in both panels. The default is |
panel_heights |
A numeric vector of length two specifying the relative
heights of the upper and lower panels. The default is |
The function displays one focal categorical predictor at a time, but the fitted model may contain additional predictors.
Models in which the focal predictor is involved in an interaction are not currently supported.
Treatment and Sum contrasts are displayed as independent pairs to improve readability. Other supported contrast types reuse repeated displayed quantities where appropriate.
Polynomial contrasts, generated by stats::contr.poly() with equally
spaced or user-supplied scores, use a dedicated layout, because each
component involves every level rather than a comparison between two
quantities. The upper panel contains one facet per component (linear,
quadratic, and so forth): each shows the level estimates with their
confidence intervals and the curve implied by that component alone,
drawn around the mean of the estimates on the linear-predictor scale and
transformed to the scale of the estimates. Crosses mark the value of the
curve at each level, which is Polynomial_fit in the output of
contrasts_onepred(). Levels are spaced according to the scores of the
coding. The lower panel shows each coefficient beneath the facet of its
component. per_difference is ignored, with a warning, because
polynomial coefficients have no scale factor.
No model-intercept line is displayed.
When show_coef = FALSE, a ggplot object containing the upper panel.
When show_coef = TRUE, a patchwork object containing the aligned upper and
lower panels.
In both cases the object carries recommended export dimensions, used by
moplot_export() when width or height is not supplied.
set.seed(123)
dat <- data.frame(
group = factor(
rep(c("A", "B", "C"), each = 40),
levels = c("A", "B", "C")
),
y = c(
rnorm(40, 0.0, 0.9),
rnorm(40, 0.4, 0.9),
rnorm(40, 0.9, 0.9)
)
)
contrasts(dat$group) <- contr.helmert(3)
mod <- lm(
y ~ group,
data = dat
)
moplot_onepred(
model = mod,
predictor = "group"
)
moplot_onepred(
model = mod,
predictor = "group",
show_data = TRUE,
style = "publication"
)
moplot_onepred(
model = mod,
predictor = "group",
show_coef = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.