View source: R/estimate_proportion.R
estimate_proportion | R Documentation |
The analyze function estimate_proportion()
creates a layout element to estimate the proportion of responders
within a studied population. The primary analysis variable, vars
, indicates whether a response has occurred for
each record. See the method
parameter for options of methods to use when constructing the confidence interval of
the proportion. Additionally, a stratification variable can be supplied via the strata
element of the variables
argument.
estimate_proportion(
lyt,
vars,
conf_level = 0.95,
method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsonc", "strat_wilson",
"strat_wilsonc", "agresti-coull", "jeffreys"),
weights = NULL,
max_iterations = 50,
variables = list(strata = NULL),
long = FALSE,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
s_proportion(
df,
.var,
conf_level = 0.95,
method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsonc", "strat_wilson",
"strat_wilsonc", "agresti-coull", "jeffreys"),
weights = NULL,
max_iterations = 50,
variables = list(strata = NULL),
long = FALSE
)
a_proportion(
df,
.var,
conf_level = 0.95,
method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsonc", "strat_wilson",
"strat_wilsonc", "agresti-coull", "jeffreys"),
weights = NULL,
max_iterations = 50,
variables = list(strata = NULL),
long = FALSE
)
lyt |
( |
vars |
( |
conf_level |
( |
method |
( |
weights |
( |
max_iterations |
( |
variables |
(named |
long |
( |
na_str |
( |
nested |
( |
... |
additional arguments for the lower level functions. |
show_labels |
( |
table_names |
( |
.stats |
( |
.formats |
(named |
.labels |
(named |
.indent_mods |
(named |
df |
( |
.var |
( |
estimate_proportion()
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_proportion()
to the table layout.
s_proportion()
returns statistics n_prop
(n
and proportion) and prop_ci
(proportion CI) for a
given variable.
a_proportion()
returns the corresponding list with formatted rtables::CellValue()
.
estimate_proportion()
: Layout-creating function which can take statistics function arguments
and additional format arguments. This function is a wrapper for rtables::analyze()
.
s_proportion()
: Statistics function estimating a
proportion along with its confidence interval.
a_proportion()
: Formatted analysis function which is used as afun
in estimate_proportion()
.
h_proportions
dta_test <- data.frame(
USUBJID = paste0("S", 1:12),
ARM = rep(LETTERS[1:3], each = 4),
AVAL = rep(LETTERS[1:3], each = 4)
)
basic_table() %>%
split_cols_by("ARM") %>%
estimate_proportion(vars = "AVAL") %>%
build_table(df = dta_test)
# Case with only logical vector.
rsp_v <- c(1, 0, 1, 0, 1, 1, 0, 0)
s_proportion(rsp_v)
# Example for Stratified Wilson CI
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(
df = dta,
.var = "rsp",
variables = list(strata = c("f1", "f2")),
conf_level = 0.90,
method = "strat_wilson"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.