The inference layers of infereportR draw statistics but do not
compute them: they run named infercalcR procedures and label the results
with the reporting functions of the package. Every estimate, interval,
test statistic, p-value and adjustment comes from
infercalcR::run_inference() and
infercalcR::adjust_inference(), and every number in a label
is a display string from report_table(). The layers choose
positions, draw the geometry and keep the complete result objects with
the figure, so that they can be inspected and reported.
All five layers run per panel when the plot is built. Rows with
non-finite x or y are dropped first, as ggplot2 does for drawing. Like
the theme, every layer takes mode = "light" or
"dark" and transparent; pass the same values
as to theme_figure() so that the ink matches the
background.
stat_means() draws the mean and its confidence interval
for every x position. The numbers are the estimate and interval of the
one-sample t procedure (t_mean_one_sample), used as an
interval estimate, not as a test.
base <- ggplot(PlantGrowth, aes(group, weight)) +
geom_point(shape = 1, position = position_jitter(width = 0.08, height = 0, seed = 1)) +
theme_figure() +
labs(x = "Group", y = "Dried weight (g)")
base + stat_means(conf.level = 0.95)stat_compare() compares x groups pairwise with a named
two-sample procedure, adjusts the family of comparisons as declared and
draws one bracket per pair. For the pair c(A, B) the
contrast is B minus A. With reference, every other level is
compared with that level; with comparisons, exactly the
listed pairs; with neither, all pairs in level order.
base +
stat_means() +
stat_compare(method = "t_means_two_independent_welch", reference = "ctrl",
adjust = "holm")The label is the p-value by default.
label = "estimate_ci" shows the difference with its
interval, "estimate_ci_p" both, and "stars"
replaces p-values below 0.05 with stars. A p-value of 0.05 or more keeps
its display string; it is never shown as “ns”.
base +
stat_compare(method = "t_means_two_independent_welch",
comparisons = list(c("trt1", "trt2")), adjust = "none",
label = "estimate_ci_p")The supported methods are
"t_means_two_independent_welch",
"t_means_two_independent_student",
"rank_sum_mann_whitney" and
"brunner_munzel".
The brackets are stacked above the data in fractions of the panel’s y
range: the first sits first = 0.10 above the highest value,
each further one step = 0.20 higher, which leaves room for
one label line between them. headroom (in steps, 1 by
default) reserves room above the top bracket, so the y scale includes
its label and nothing is clipped; with headroom = 2 a label
at the top of the panel, such as an omnibus test, clears the top
bracket.
stat_omnibus() runs one omnibus test per panel, with y
as the outcome and the x positions as groups, and writes the estimand,
test statistic and p-value in the top left corner. The methods are
"anova_one_way", "anova_one_way_welch" and
"kruskal_wallis". Degrees of freedom are not part of the
label, because report_table() has no display string for
them; they are in the result.
stat_correlation() runs one correlation per panel and
labels the coefficient, its interval and the p-value. The methods are
"correlation_pearson", "correlation_spearman"
and "correlation_kendall". With fit = TRUE it
also draws the fitted mean line of infercalcR’s linear prediction model
(prediction_model_linear) with its pointwise confidence
band from infercalcR::predict_inference(interval = "mean"),
as dotted lines without fill. The fit treats every row as an independent
unit, and the line is never fitted with lm() directly. With
fit = TRUE the function returns two layers, which
+ adds together. The label stands top left by default; the
association is negative here, so it is moved to the free top right
corner.
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 1) +
stat_correlation(method = "correlation_pearson", fit = TRUE,
label_x = Inf, hjust = 1) +
theme_figure() +
labs(x = "Weight (1000 lb)", y = "Fuel economy (mpg)")label = "estimate_ci_p_n" writes the label on two lines,
the coefficient with its interval on the first and the p-value with the
number of pairs on the second, both formatted by
report_table(). infercalcR computes a correlation from 4
pairs on; the fitted line of fit = TRUE needs at least 20
pairs per panel. Spearman and Kendall correlations come without an
interval in infercalcR 0.1.0, and the label then leaves the interval
out.
The label of such a figure, read back from the layer data, is:
two_line <- ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 1) +
stat_correlation(method = "correlation_pearson", label = "estimate_ci_p_n",
label_x = Inf, hjust = 1)
cat(layer_data(two_line, 2L)$label, sep = "\n")
#> r = -0.868 [-0.934, -0.744]
#> p < 0.001, n = 32The label layers place their text at the panel edges
(-Inf and Inf), 1 mm inside the panel. Always
draw them together with a data layer, such as the points here, so that
ggplot2 has data to train the position scales on.
stat_paired() draws a design with two measurements per
unit, such as before and after: x is discrete with exactly two levels
(first “before”, second “after”), and the new aesthetic id
names the unit. The layer runs one paired procedure per panel,
"t_means_paired" or "signed_rank_wilcoxon", on
the units with both values, so the contrast is after minus before. It
draws one thin line per unit, open points at both ends, the two level
means joined by a heavy line and, right of the second level, a label
with the change, its interval and the p-value. The means are geometry;
every printed number is a report_table() display string.
Here are the two drugs of the sleep data of Student (1908), given to the
same ten people:
sleep_long <- transform(sleep, drug = factor(group, labels = c("Drug 1", "Drug 2")))
ggplot(sleep_long, aes(drug, extra, id = ID)) +
stat_paired(method = "t_means_paired", unit = "h") +
coord_cartesian(clip = "off") +
theme_figure() +
theme(plot.margin = margin(2, 21, 2, 2, unit = "mm")) +
labs(x = NULL, y = "Extra sleep (h)")The label sits beside the second level and extends beyond the panel,
hence clip = "off" and the wider right margin.
Two functions build a complete figure from inference results rather
than adding a layer. figure_forest() takes a named list of
infercalcR results, one contrast each, and draws a forest plot laid out
for a slide slot (slot = "slide_full", 134 x 44 mm, by
default): a label, n and the estimate with its interval as text columns,
square markers with area proportional to n and a dotted line at the null
value. Here the tooth growth difference between orange juice and
ascorbic acid, overall and per dose:
welch <- infercalcR::method_spec("t_means_two_independent_welch")
difference <- function(d) {
infercalcR::run_inference(welch, x = d$len[d$supp == "OJ"], y = d$len[d$supp == "VC"])
}
by_dose <- lapply(split(ToothGrowth, ToothGrowth$dose), difference)
results <- c(list("All doses" = difference(ToothGrowth)),
setNames(by_dose, paste(names(by_dose), "mg/day")))
figure_forest(results, xlab = "Orange juice minus ascorbic acid (mm)",
header = c("Dose", "n", "Difference [95% CI]"))The first result is the overall row, set in bold above a hairline
(overall = 1). figure_correlation_matrix()
runs one named correlation procedure for every pair of variables and
shows the strength as circle area above the diagonal (filled for
positive, open for negative) and the values below it:
figure_correlation_matrix(mtcars, vars = c("mpg", "wt", "hp", "qsec"),
method = "correlation_spearman")Both builders keep their results like the layers do, so
inference_results() and figure_table() work on
them.
The suite never chooses a procedure from the data.
stat_compare(), stat_omnibus(),
stat_correlation(), stat_paired() and the two
figure builders have no default method, so leaving it out is an error
when the layer is created:
res <- try(stat_compare(reference = "ctrl", adjust = "holm"), silent = TRUE)
cat(res)
#> Error : method is missing: choose the procedure explicitly; infereportR never selects a test from the dataWith more than one comparison, the multiplicity adjustment must be
declared; adjust = "none" is allowed and documents the
choice. With explicit comparisons, the layer checks this
when it is created:
res <- try(stat_compare(method = "t_means_two_independent_welch",
comparisons = list(c("ctrl", "trt1"), c("ctrl", "trt2"))),
silent = TRUE)
cat(res)
#> Error : adjust is missing: declare the multiplicity adjustment; 'none' is allowedWith reference or all pairs, the number of comparisons
is only known when the plot is built. ggplot2 then reports “Problem
while computing stat”, with the infereportR condition as the cause:
p <- base + stat_compare(method = "t_means_two_independent_welch")
res <- try(ggplot_build(p), silent = TRUE)
cat(res)
#> Error in stat_compare(method = "t_means_two_independent_welch") :
#> Problem while computing stat.
#> ℹ Error occurred in the 2nd layer.
#> Caused by error:
#> ! adjust is missing: declare the multiplicity adjustment; 'none' is allowedThe error conditions have classes such as
infereportR_invalid_input, so code can catch them with
tryCatch().
Every panel is its own analysis: stat_means() estimates
per panel and x level, stat_compare() forms one comparison
family per panel, and stat_omnibus() and
stat_correlation() run once per panel. Here each supplement
has its own Holm family of three dose comparisons:
tooth <- ToothGrowth
tooth$dose <- factor(tooth$dose)
tooth$supp <- factor(tooth$supp, labels = c("Orange juice", "Ascorbic acid"))
facetted <- ggplot(tooth, aes(dose, len)) +
geom_point(shape = 1, position = position_jitter(width = 0.08, height = 0, seed = 1)) +
stat_means() +
stat_compare(method = "t_means_two_independent_welch", adjust = "holm") +
facet_wrap(~supp) +
theme_figure() +
labs(x = "Dose (mg/day)", y = "Tooth length (mm)")
facettedinference_results() builds the plot once and returns
every infercalcR result its layers computed, named by layer, method and
panel:
results <- inference_results(facetted)
names(results)
#> [1] "infereportR:means:t_mean_one_sample:panel1:0.5"
#> [2] "infereportR:means:t_mean_one_sample:panel1:1"
#> [3] "infereportR:means:t_mean_one_sample:panel1:2"
#> [4] "infereportR:means:t_mean_one_sample:panel2:0.5"
#> [5] "infereportR:means:t_mean_one_sample:panel2:1"
#> [6] "infereportR:means:t_mean_one_sample:panel2:2"
#> [7] "infereportR:compare:t_means_two_independent_welch:panel1"
#> [8] "infereportR:compare:t_means_two_independent_welch:panel2"These are ordinary infercalcR result objects. infercalcR and the reporting functions read them as they would read any other result, for example as a sentence for the manuscript:
oj <- results[["infereportR:compare:t_means_two_independent_welch:panel1"]]
infercalcR::result_data(oj)[, c("row_id", "estimate", "p.value", "p.adjusted")]
#> row_id estimate p.value p.adjusted
#> 1 1-0.5 9.47 8.784919e-05 1.756984e-04
#> 2 2-0.5 12.83 1.323784e-06 3.971352e-06
#> 3 2-1 3.36 3.919514e-02 3.919514e-02
cat(report_text(oj, p = "adjusted"), sep = "\n\n")
#> t_means_two_independent_welch; mean difference (x minus reference or y); 1 minus 0.5: estimate 9.47; 95% interval [5.52, 13.4] (Welch t; identity; pointwise); statistic 5.05; p < 0.001 (adjusted); recorded adjustment: holm; n = 20; excluded = 0.
#>
#> t_means_two_independent_welch; mean difference (x minus reference or y); 2 minus 0.5: estimate 12.8; 95% interval [9.32, 16.3] (Welch t; identity; pointwise); statistic 7.82; p < 0.001 (adjusted); recorded adjustment: holm; n = 20; excluded = 0.
#>
#> t_means_two_independent_welch; mean difference (x minus reference or y); 2 minus 1: estimate 3.36; 95% interval [0.189, 6.53] (Welch t; identity; pointwise); statistic 2.25; p = 0.039 (adjusted); recorded adjustment: holm; n = 20; excluded = 0.figure_table()figure_table() passes every result through
report_table() and binds the rows, with the layer and panel
each one came from. By default (p = "auto") it reports
adjusted p-values where a result has an adjustment and raw ones
elsewhere.
tab <- figure_table(facetted)
tab[tab$figure_layer == 3, c("figure_panel", "contrast", "estimate_display",
"interval_display", "p_display")]
#> figure_panel contrast estimate_display interval_display p_display
#> 7 1 1 minus 0.5 9.47 [5.52, 13.4] p < 0.001
#> 8 1 2 minus 0.5 12.8 [9.32, 16.3] p < 0.001
#> 9 1 2 minus 1 3.36 [0.189, 6.53] p = 0.039
#> 10 2 1 minus 0.5 8.79 [6.31, 11.3] p < 0.001
#> 11 2 2 minus 0.5 18.2 [14.4, 21.9] p < 0.001
#> 12 2 2 minus 1 9.37 [5.69, 13.1] p < 0.001report_figure() bundlereport_figure() adds the theme, the black-and-white
scales, the raw observations, the means and the tests you name, in one
call. It adds no test unless its procedure is named:
bundle <- ggplot(PlantGrowth, aes(group, weight)) +
report_figure(compare = "t_means_two_independent_welch", reference = "ctrl",
adjust = "holm", omnibus = "anova_one_way") +
labs(x = "Group", y = "Dried weight (g)")
bundleWith points = "jitter" (the default) the means are drawn
a little to the right of the raw observations, so the two never overlap.
With an omnibus test, report_figure() reserves two steps of
headroom above the brackets, so the omnibus label at the top of the
panel clears the top bracket label.
stat_inference()Results computed elsewhere can be drawn on the same figure with
stat_inference(), which takes a finished result and
explicit bracket positions. Here infercalcR runs a Brunner-Munzel test
of trt2 against trt1:
pg <- PlantGrowth
bm <- infercalcR::run_inference(
infercalcR::method_spec("brunner_munzel"),
x = pg$weight[pg$group == "trt2"], y = pg$weight[pg$group == "trt1"],
result_id = "bm-trt2-trt1")
row_id <- infercalcR::result_data(bm)$row_id
positions <- data.frame(row_id = row_id, group1 = "trt1", group2 = "trt2",
y_position = 6.6)
base +
stat_means() +
stat_inference(bm, positions, groups = levels(pg$group),
text_size = 9 / .pt)The precomputed result is not part of
inference_results(), which returns only what the inference
layers computed.
vignette("comparison-families", package = "infereportR")
shows the same family drawn both ways and explains when to use
which.
The calculations are those of infercalcR (Heller, https://github.com/CTTIR/infercalcR) and the display
strings those of the reporting functions of infereportR. The ggproto
objects follow the public ggplot2 extension guide,
vignette("extending-ggplot2", package = "ggplot2"). The
sleep data are those of Student (1908), The probable error of a
mean, Biometrika 6(1), 1-25, as shipped with R. See the README for
the full list of sources.
This package is part of an inference suite (infercalcR, inferguidR and infereportR) that is deeply inspired by DescrTab2 [1], developed at the Institute of Medical Biometry (IMBI), Heidelberg University, by Jan Meis, Lukas Baumann, Maximilian Pilz and Lukas Sauer. Its test-choice tree, its validation statement and its practice of computing each test with an established implementation are the model for how the suite chooses, computes and reports statistical tests. DescrTab2 was archived on CRAN on 18 October 2025; its source code remains available on GitHub. The methods-consulting pages of the University of Zurich [2], with their decision tree, decision assistant, worked examples and explanations, inspired the guidance in the suite. Power and sample-size planning and the distribution calculator follow G*Power 3.1 [3, 4]. We thank the authors of these works for making them openly available. The package README cites all software the package uses.