Add between-group comparison rows to a tbl_proportion() table.

  • add_proportion_difference() adds a block with the difference in response rates, its confidence interval, and a test p-value.

  • add_proportion_odds_ratio() adds an odds-ratio row (with confidence interval).

Both verbs compare every non-reference group against reference. Supplying strata switches the p-value (and odds ratio) to their stratified (Cochran-Mantel-Haenszel) counterparts, so an unstratified and a stratified block can be stacked by calling the verb twice.

All statistical choices (test, method, confidence level, continuity correction) live on these functions. Row wording is overridable through the label arguments.

add_proportion_difference(
  x,
  reference = NULL,
  test = c("chisq", "fisher", "cmh"),
  strata = NULL,
  conf.level = 0.95,
  correct = TRUE,
  test_correct = FALSE,
  header = NULL,
  diff_label = "Difference in Response rate (%)",
  pvalue_label = NULL,
  ci_label = NULL,
  estimate_fun = label_roche_number(digits = 1),
  pvalue_fun = label_roche_pvalue()
)

add_proportion_odds_ratio(
  x,
  reference = NULL,
  strata = NULL,
  conf.level = 0.95,
  or_label = NULL,
  estimate_fun = label_roche_ratio()
)

Arguments

x

(tbl_proportion)
a table created by tbl_proportion() on a binary variable (built with the value argument).

reference

(string)
value of the by variable used as reference. Defaults to the first level.

test

(string)
test for the p-value: "chisq" (Chi-squared, default), "fisher" (Fisher's exact), or "cmh" (Cochran-Mantel-Haenszel, requires strata).

strata

(string)
optional stratification variable; when supplied the p-value uses CMH and the default header becomes "Stratified Analysis". Default NULL.

conf.level

(scalar)
confidence level. Default 0.95.

correct

(flag)
continuity correction for the difference confidence interval (the "Wald, with continuity correction" interval from stats::prop.test()). Default TRUE.

test_correct

(flag)
Yates continuity correction for the chi-squared test p-value. Default FALSE, matching the NEST 1.0 catalog (RSPT01). Has no effect on the Fisher or CMH tests.

header, diff_label, pvalue_label, ci_label

(string)
row labels. header defaults to "Unstratified Analysis" / "Stratified Analysis"; pvalue_label and ci_label are derived from test, conf.level and correct when NULL.

estimate_fun, pvalue_fun

(function)
formatters for the difference/CI values and the p-value.

or_label

(string)
label for the odds-ratio row. Default "Odds Ratio (95% CI)".

Value

the input tbl_proportion with comparison rows appended.

Functions

See also

Examples

set.seed(1)
df <- data.frame(
  arm = factor(sample(c("A", "B", "C"), 200, TRUE), levels = c("A", "B", "C")),
  rsp = sample(c(TRUE, FALSE), 200, TRUE)
)
tbl_proportion(df, "rsp", "arm", value = TRUE) |>
  add_proportion_difference(reference = "A") |>
  add_proportion_odds_ratio(reference = "A")
Characteristic A B C
Responders 29 (43.9%) 39 (57.4%) 33 (50.0%)
    95% CI (Wald, with continuity correction) (31.2, 56.7) (44.9, 69.8) (37.2, 62.8)
Unstratified Analysis


    Difference in Response rate (%)
13.4 6.1
        95% CI (Wald, with continuity correction)
(-4.9, 31.7) (-12.5, 24.6)
    p-value (Chi-Squared Test)
0.1205 0.4854
    Odds Ratio (95% CI)
1.72 (0.87, 3.42) 1.28 (0.64, 2.54)