Skip to contents

Produces a forest plot from the $Contrasts component of a waldTest() result. A forest plot requires an estimate and standard error for each row, so joint zero tests (which have neither) cannot be displayed. If res contains only zero-test results an error is raised; if it contains both contrast and zero-test results a warning is issued and the zero results are dropped.

Each contrast is shown as a filled circle with horizontal confidence interval bars. Points are coloured by \(-\log_{10}(p)\): non-significant results (p \(\geq\) alpha) appear in grey; significant results follow a warm gradient from gold through to dark red as evidence strengthens. The raw p-value is printed beside each row. A vertical dashed line marks \(x = 0\).

Usage

plot_waldTest(
  res,
  facet = TRUE,
  ci_level = 0.95,
  alpha = 0.05,
  theme = ggplot2::theme_bw(),
  return_data = FALSE,
  ...
)

Arguments

res

List returned by waldTest().

facet

Logical. When waldTest() was called with a by argument, TRUE (default) produces one facet panel per group with free y-scales; FALSE places all groups on a single panel separated by dotted horizontal lines.

ci_level

Numeric in (0, 1). Confidence level for the CI arms. Default 0.95.

alpha

Numeric significance threshold. Controls the colour-scale break between non-significant (grey) and significant (warm gradient) results, and the significant column in the returned data frame. Default 0.05.

theme

A ggplot2 theme object used as the base theme. Default ggplot2::theme_bw().

return_data

Logical. If TRUE, returns the tidy data frame used to build the plot rather than the ggplot object. Useful for bespoke customisation. Default FALSE.

...

Reserved for future use.

Value

A ggplot2::ggplot object returned invisibly (so it can be extended with +), or a data frame when return_data = TRUE.

See also

Examples

if (FALSE) { # \dontrun{
## Pairwise contrasts, no by-group
res <- waldTest(pred,
  cc = list(list(coef = c("N0","N1","N2"), type = "con", comp = "pairwise")))
plot_waldTest(res)

## By-group — one panel per site (default)
res2 <- waldTest(pred_site,
  cc = list(list(coef = c("N0","N1","N2"), type = "con", comp = "pairwise")),
  by = "Site")
plot_waldTest(res2, facet = TRUE)

## By-group — all sites on one panel with separator lines
plot_waldTest(res2, facet = FALSE)

## 99% CI
plot_waldTest(res, ci_level = 0.99)

## Stricter significance threshold
plot_waldTest(res, alpha = 0.01)

## Return tidy data for bespoke use
df <- plot_waldTest(res, return_data = TRUE)
} # }