Usage
s_proportion_diff(
df,
.var,
.ref_group,
.in_ref_col,
variables = list(strata = NULL),
conf_level = 0.95,
method = c("waldcc", "wald", "cmh", "ha", "newcombe", "newcombecc", "strat_newcombe",
"strat_newcombecc"),
weights_method = "cmh"
)
a_proportion_diff(
df,
.var,
.ref_group,
.in_ref_col,
variables = list(strata = NULL),
conf_level = 0.95,
method = c("waldcc", "wald", "cmh", "ha", "newcombe", "newcombecc", "strat_newcombe",
"strat_newcombecc"),
weights_method = "cmh"
)
estimate_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.- conf_level
(
proportion
)
confidence level of the interval.- method
(
string
)
the method used for the confidence interval estimation.- weights_method
(
string
)
weights method. Can be either"cmh"
or"heuristic"
and directs the way weights are estimated.- lyt
(
layout
)
input layout where analyses will be added to.- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- ...
arguments passed to
s_proportion_diff()
.- var_labels
character for label.
- show_labels
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.
Functions
s_proportion_diff()
: Statistics function estimating the difference in terms of responder proportion.a_proportion_diff()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.estimate_proportion_diff()
: Adds a descriptive analyze layer tortables
pipelines. The analysis is applied to adataframe
and return the estimations, inrcells
. The ellipsis (...
) conveys arguments tos_proportion_diff()
, for instancena.rm = FALSE
if missing data should be accounted for.
Examples
# Summary
## "Mid" case: 4/4 respond in group A, 1/2 respond in group B.
nex <- 100 # Number of example rows
dta <- data.frame(
"rsp" = sample(c(TRUE, FALSE), nex, TRUE),
"grp" = sample(c("A", "B"), nex, TRUE),
"f1" = sample(c("a1", "a2"), nex, TRUE),
"f2" = sample(c("x", "y", "z"), nex, TRUE),
stringsAsFactors = TRUE
)
s_proportion_diff(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
conf_level = 0.90,
method = "ha"
)
#> $diff
#> [1] -8.05153
#> attr(,"label")
#> [1] "Difference in Response rate (%)"
#>
#> $diff_ci
#> [1] -25.754477 9.651418
#> attr(,"label")
#> [1] "90% CI (Anderson-Hauck)"
#>
# CMH example with strata
s_proportion_diff(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
variables = list(strata = c("f1", "f2")),
conf_level = 0.90,
method = "cmh"
)
#> $diff
#> [1] -8.240459
#> attr(,"label")
#> [1] "Difference in Response rate (%)"
#>
#> $diff_ci
#> [1] -24.002675 7.521757
#> attr(,"label")
#> [1] "90% CI (CMH, without correction)"
#>
a_proportion_diff(
df = subset(dta, grp == "A"),
.var = "rsp",
.ref_group = subset(dta, grp == "B"),
.in_ref_col = FALSE,
conf_level = 0.90,
method = "ha"
)
#> RowsVerticalSection (in_rows) object print method:
#> ----------------------------
#> row_name formatted_cell indent_mod row_label
#> 1 diff -8.1 0 Difference in Response rate (%)
#> 2 diff_ci (-25.8, 9.7) 1 90% CI (Anderson-Hauck)
l <- basic_table() %>%
split_cols_by(var = "grp", ref_group = "B") %>%
estimate_proportion_diff(
vars = "rsp",
conf_level = 0.90,
method = "ha"
)
build_table(l, df = dta)
#> B A
#> ——————————————————————————————————————————————————
#> Difference in Response rate (%) -8.1
#> 90% CI (Anderson-Hauck) (-25.8, 9.7)