The analyze function test_proportion_diff()
creates a layout element to test the difference between two
proportions. The primary analysis variable, vars
, indicates whether a response has occurred for each record. See
the method
parameter for options of methods to use to calculate the p-value. Additionally, a stratification
variable can be supplied via the strata
element of the variables
argument.
test_proportion_diff(
lyt,
vars,
variables = list(strata = NULL),
method = c("chisq", "schouten", "fisher", "cmh"),
na_str = default_na_str(),
nested = TRUE,
...,
var_labels = vars,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)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()
returns a layout object suitable for passing to further layouting functions,
or to rtables::build_table()
. Adding this function to an rtable
layout will add formatted rows containing
the statistics from s_test_proportion_diff()
to the table layout.
s_test_proportion_diff()
returns a named list
with a single item pval
with an attribute label
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 formatted rtables::CellValue()
.
(PreDataTableLayouts
)
layout that analyses will be added to.
(character
)
variable names for the primary analysis variable to be iterated over.
(named list
of string
)
list of additional analysis variables.
(string
)
one of chisq
, cmh
, fisher
, or schouten
; specifies the test used
to calculate the p-value.
(string
)
string used to replace all NA
or empty values in the output.
(flag
)
whether this layout instruction should be applied within the existing layout structure _if
possible (TRUE
, the default) or as a new top-level element (FALSE
). Ignored if it would nest a split.
underneath analyses, which is not allowed.
additional arguments for the lower level functions.
(character
)
variable labels.
(string
)
label visibility: one of "default", "visible" and "hidden".
(character
)
this can be customized in the case that the same vars
are analyzed multiple
times, to avoid warnings from rtables
.
(character
)
statistics to select for the table.
Options are: 'pval'
(named character
or list
)
formats for the statistics. See Details in analyze_vars
for more
information on the "auto"
setting.
(named character
)
labels for the statistics (without indent).
(named integer
)
indent modifiers for the labels. Defaults to 0, which corresponds to the
unmodified default behavior. Can be negative.
(data.frame
)
data set containing all analysis variables.
(string
)
single variable name that is passed by rtables
when requested
by a statistics function.
(data.frame
or vector
)
the data corresponding to the reference group.
(flag
)
TRUE
when working with the reference level, FALSE
otherwise.
test_proportion_diff()
: Layout-creating function which can take statistics function arguments
and additional format arguments. This function is a wrapper for rtables::analyze()
.
s_test_proportion_diff()
: Statistics function which tests the difference between two proportions.
a_test_proportion_diff()
: Formatted analysis function which is used as afun
in test_proportion_diff()
.
h_prop_diff_test
dta <- data.frame(
rsp = sample(c(TRUE, FALSE), 100, TRUE),
grp = factor(rep(c("A", "B"), each = 50)),
strata = factor(rep(c("V", "W", "X", "Y", "Z"), each = 20))
)
# With `rtables` pipelines.
l <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "B") %>%
test_proportion_diff(
vars = "rsp",
method = "cmh", variables = list(strata = "strata")
)
build_table(l, df = dta)
Run the code above in your browser using DataLab