make_annotations: Make Annotations for Significance Brackets

View source: R/functions.R

make_annotationsR Documentation

Make Annotations for Significance Brackets

Description

Makes a list of annotations for significance brakcets produced by the geom_signif() function from the ggsignif package. The annotations are added for pairs of estimates whose confidence intervals overlap, but the estimates are nonetheless significantly different from each other.

Usage

make_annotations(
  obj,
  type = c("auto", "significant", "insignificant", "discrepancies"),
  tol = 0,
  nudge = NULL,
  ...
)

Arguments

obj

An object of class viztest produced by the viztest() function.

type

Indicates whether annotations are produced for overlapping intervals that are significantly different from each other or not. The "auto" option will find the type that produces the fewest annotations. If type="discrepancies", annotations will be made for pairs of estimates whose test results do not correspond with the (non-)overlaps in the confidence intervals.

tol

Tolerance for determining whether intervals are close enough to be considered ambiguous. This also plots significance flags for intervals that do not overlap, but the distance between them is smaller than the tolerance. The default is zero, but increasing the value will potentially produce more significance flags.

nudge

A vector of the same length as the number of brackets. This will nudge the y-position of the brakcet by the indicated amount. This will be difficult to specify ahead of time, but can be specified to clean up a plot after an initial run.

...

Other arguments, currently ignored.

Examples

data(chickwts)
chick_mod <- lm(weight ~ feed, data=chickwts)
library(marginaleffects)
chick_preds <- avg_predictions(chick_mod, variables="feed")
b <- coef(chick_preds)
names(b) <- chick_preds$feed
v <- vcov(chick_preds)
chick_vt_data <- make_vt_data(b, v)
chick_vt <- viztest(chick_vt_data, test_level = 0.0001, include_zero=FALSE)
chick_vt

make_annotations(chick_vt, type="discrepancies")

VizTest documentation built on Dec. 4, 2025, 9:07 a.m.