prop_diff_test {junco} | R Documentation |
Difference test for two proportions
Description
The analysis function a_test_proportion_diff()
can be used to create 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. The argument alternative
specifies the direction of the
alternative hypothesis.
Usage
a_test_proportion_diff(
df,
.var,
ref_path,
.spl_context,
...,
.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", "fisher", "cmh"),
alternative = c("two.sided", "less", "greater")
)
Arguments
df |
( |
.var |
( |
ref_path |
( |
.spl_context |
( |
... |
additional arguments for the lower level functions. |
.stats |
( |
.formats |
(named |
.labels |
(named |
.indent_mods |
(named |
.ref_group |
( |
.in_ref_col |
( |
variables |
(named |
method |
( |
alternative |
( |
Value
-
a_test_proportion_diff()
returns the corresponding list with formattedrtables::CellValue()
.
-
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.
Functions
-
a_test_proportion_diff()
: Formatted analysis function which is used asafun
-
s_test_proportion_diff()
: Statistics function which tests the difference between two proportions.
Note
These functions have been forked from the tern
package. Additional features are:
Additional
alternative
argument for the sidedness of the test.Additional
ref_path
argument for flexible reference column path specification.
See Also
Examples
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))
)
l <- basic_table() |>
split_cols_by(var = "grp") |>
analyze(
vars = "rsp",
afun = a_test_proportion_diff,
show_labels = "hidden",
extra_args = list(
method = "cmh",
variables = list(strata = "strata"),
ref_path = c("grp", "B")
)
)
build_table(l, df = dta)