Usage
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
)
estimate_proportion(
lyt,
vars,
...,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)Arguments
- df
(
logicalordata.frame)
if only a logical vector is used, it indicates whether each subject is a responder or not.TRUErepresents a successful outcome. If adata.frameis provided, also thestratavariable names must be provided invariablesas a list element with the strata strings. In the case ofdata.frame, the logical vector of responses must be indicated as a variable name in.var.- .var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.- conf_level
(
proportion)
confidence level of the interval.- method
(
string)
the method used to construct the confidence interval for proportion of successful outcomes; one ofwaldcc,wald,clopper-pearson,wilson,wilsonc,strat_wilson,strat_wilsonc,agresti-coullorjeffreys.- weights
(
numericorNULL)
weights for each level of the strata. IfNULL, they are estimated using the iterative algorithm proposed in Yan and Su (2010) that minimizes the weighted squared length of the confidence interval.- max_iterations
(
count)
maximum number of iterations for the iterative procedure used to find estimates of optimal weights.- variables
(named
listofstring)
list of additional analysis variables.- long
(
flag)
a long description is required.- 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 ultimately conveyed to
s_proportion().- show_labels
(
string)
label visibility: one of "default", "visible" and "hidden".- table_names
(
character)
this can be customized in case that the samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table.- .formats
(named
characterorlist)
formats for the statistics.- .labels
(named
character)
labels for the statistics (without indent).- .indent_mods
(named
integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.
Value
s_proportion()returns statisticsn_prop(nand proportion) andprop_ci(proportion CI) for a given variable.
a_proportion()returns the corresponding list with formattedrtables::CellValue().
estimate_proportion()returns a layout object suitable for passing to further layouting functions, or tortables::build_table(). Adding this function to anrtablelayout will add formatted rows containing the statistics froms_proportion()to the table layout.
Functions
s_proportion(): Statistics function estimating a proportion along with its confidence interval.a_proportion(): Formatted analysis function which is used asafuninestimate_proportion().estimate_proportion(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze().
Examples
# Case with only logical vector.
rsp_v <- c(1, 0, 1, 0, 1, 1, 0, 0)
s_proportion(rsp_v)
#> $n_prop
#> [1] 4.0 0.5
#> attr(,"label")
#> [1] "Responders"
#>
#> $prop_ci
#> [1] 9.102404 90.897596
#> attr(,"label")
#> [1] "95% CI (Wald, with correction)"
#>
# 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"
)
#> $n_prop
#> [1] 49.00 0.49
#> attr(,"label")
#> [1] "Responders"
#>
#> $prop_ci
#> lower upper
#> 40.80675 56.65017
#> attr(,"label")
#> [1] "90% CI (Stratified Wilson, without correction)"
#>
dta_test <- data.frame(
USUBJID = paste0("S", 1:12),
ARM = rep(LETTERS[1:3], each = 4),
AVAL = c(A = c(1, 1, 1, 1), B = c(0, 0, 1, 1), C = c(0, 0, 0, 0))
)
basic_table() %>%
split_cols_by("ARM") %>%
estimate_proportion(vars = "AVAL") %>%
build_table(df = dta_test)
#> A B C
#> ———————————————————————————————————————————————————————————————————————————
#> Responders 4 (100.0%) 2 (50.0%) 0 (0.0%)
#> 95% CI (Wald, with correction) (87.5, 100.0) (0.0, 100.0) (0.0, 12.5)