Usage
s_test_proportion_diff(
df,
.var,
.ref_group,
.in_ref_col,
variables = list(strata = NULL),
method = c("chisq", "schouten", "fisher", "cmh")
)
a_test_proportion_diff(
df,
.var,
.ref_group,
.in_ref_col,
variables = list(strata = NULL),
method = c("chisq", "schouten", "fisher", "cmh")
)
test_proportion_diff(
lyt,
vars,
...,
var_labels = vars,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
Arguments
- df
(
data.frame
)
data set containing all analysis variables.- .var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- .ref_group
(
data.frame
orvector
)
the data corresponding to the reference group.- .in_ref_col
(
logical
)TRUE
when working with the reference level,FALSE
otherwise.- variables
(named
list
ofstring
)
list of additional analysis variables.- method
(
string
)
one ofchisq
,cmh
,fisher
, orschouten
; specifies the test used to calculate the p-value.- lyt
(
layout
)
input layout where analyses will be added to.- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- ...
other arguments are passed to
s_test_proportion_diff()
.- var_labels
(
character
)
character for label.- show_labels
(
string
)
label visibility: one of "default", "visible" and "hidden".- table_names
(
character
)
this can be customized in case that the samevars
are analyzed multiple times, to avoid warnings fromrtables
.- .stats
(
character
)
statistics to select for the table.- .formats
(named
character
orlist
)
formats for the statistics.- .labels
(named
character
)
labels for the statistics (without indent).- .indent_mods
(named
integer
)
indent modifiers for the labels.- tbl
(
matrix
)
matrix with two groups in rows and the binary response (TRUE
/FALSE
) in columns.
Value
s_test_proportion_diff()
returns a namedlist
with a single itempval
with an attributelabel
describing the method used. The p-value tests the null hypothesis that proportions in two groups are the same.
a_test_proportion_diff()
returns the corresponding list with formattedrtables::CellValue()
.
test_proportion_diff()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted rows containing the statistics froms_test_proportion_diff()
to the table layout.
Functions
s_test_proportion_diff()
: Statistics function which tests the difference between two proportions.a_test_proportion_diff()
: Formatted analysis function which is used asafun
intest_proportion_diff()
.test_proportion_diff()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
.
Examples
# Statistics function
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50)),
strat = factor(rep(c("V", "W", "X", "Y", "Z"), each = 20))
)
# Internal function - s_test_proportion_diff
if (FALSE) {
s_test_proportion_diff(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
variables = list(strata = "strat"),
method = "cmh"
)
}
# Internal function - a_test_proportion_diff
if (FALSE) {
a_test_proportion_diff(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
variables = list(strata = "strat"),
method = "cmh"
)
}
# With `rtables` pipelines.
l <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "B") %>%
test_proportion_diff(
vars = "rsp",
method = "cmh", variables = list(strata = "strat")
)
build_table(l, df = dta)
#> B A
#> —————————————————————————————————————————————————————
#> p-value (Cochran-Mantel-Haenszel Test) 1.0000