R/add_proportion_difference.R, R/add_proportion_odds_ratio.R
add_proportion_difference.RdAdd 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()
)(tbl_proportion)
a table created by tbl_proportion() on a binary variable (built with the
value argument).
(string)
value of the by variable used as reference. Defaults to the first level.
(string)
test for the p-value: "chisq" (Chi-squared, default), "fisher"
(Fisher's exact), or "cmh" (Cochran-Mantel-Haenszel, requires strata).
(string)
optional stratification variable; when supplied the p-value uses CMH and
the default header becomes "Stratified Analysis". Default NULL.
(scalar)
confidence level. Default 0.95.
(flag)
continuity correction for the difference confidence interval (the
"Wald, with continuity correction" interval from stats::prop.test()).
Default TRUE.
(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.
(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.
(function)
formatters for the difference/CI values and the p-value.
(string)
label for the odds-ratio row. Default "Odds Ratio (95% CI)".
the input tbl_proportion with comparison rows appended.
add_proportion_odds_ratio(): Add an odds-ratio row (with confidence interval) comparing each non-reference
group to reference. Unstratified odds ratios come from logistic regression
(stats::glm(), via cardx::ard_regression_basic()); when strata is
supplied the common (CMH) odds ratio from stats::mantelhaen.test() is used.
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