forked from insightsengineering/tern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimate_proportions.Rd
181 lines (150 loc) · 6.43 KB
/
estimate_proportions.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/estimate_proportion.R
\name{estimate_proportions}
\alias{estimate_proportions}
\alias{estimate_proportion}
\alias{s_proportion}
\alias{a_proportion}
\title{Estimation of Proportions}
\usage{
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
)
}
\arguments{
\item{lyt}{(\code{layout})\cr input layout where analyses will be added to.}
\item{vars}{(\code{character})\cr variable names for the primary analysis variable to be iterated over.}
\item{conf_level}{(\code{proportion})\cr confidence level of the interval.}
\item{method}{(\code{string})\cr the method used to construct the confidence interval
for proportion of successful outcomes; one of \code{waldcc}, \code{wald}, \code{clopper-pearson},
\code{wilson}, \code{wilsonc}, \code{strat_wilson}, \code{strat_wilsonc}, \code{agresti-coull} or \code{jeffreys}.}
\item{weights}{(\code{numeric} or \code{NULL})\cr weights for each level of the strata. If \code{NULL}, they are
estimated using the iterative algorithm proposed in \insertCite{Yan2010-jt;textual}{tern} that
minimizes the weighted squared length of the confidence interval.}
\item{max_iterations}{(\code{count})\cr maximum number of iterations for the iterative procedure used
to find estimates of optimal weights.}
\item{variables}{(named \code{list} of \code{string})\cr list of additional analysis variables.}
\item{long}{(\code{flag})\cr a long description is required.}
\item{na_str}{(\code{string})\cr string used to replace all \code{NA} or empty values in the output.}
\item{nested}{(\code{flag})\cr whether this layout instruction should be applied within the existing layout structure \emph{if
possible} (\code{TRUE}, the default) or as a new top-level element (\code{FALSE}). Ignored if it would nest a split.
underneath analyses, which is not allowed.}
\item{...}{additional arguments for the lower level functions.}
\item{show_labels}{(\code{string})\cr label visibility: one of "default", "visible" and "hidden".}
\item{table_names}{(\code{character})\cr this can be customized in case that the same \code{vars} are analyzed multiple times,
to avoid warnings from \code{rtables}.}
\item{.stats}{(\code{character})\cr statistics to select for the table. Run \code{get_stats("estimate_proportion")}
to see available statistics for this function.}
\item{.formats}{(named \code{character} or \code{list})\cr formats for the statistics. See Details in \code{analyze_vars} for more
information on the \code{"auto"} setting.}
\item{.labels}{(named \code{character})\cr labels for the statistics (without indent).}
\item{.indent_mods}{(named \code{integer})\cr indent modifiers for the labels. Defaults to 0, which corresponds to the
unmodified default behavior. Can be negative.}
\item{df}{(\code{logical} or \code{data.frame})\cr if only a logical vector is used,
it indicates whether each subject is a responder or not. \code{TRUE} represents
a successful outcome. If a \code{data.frame} is provided, also the \code{strata} variable
names must be provided in \code{variables} as a list element with the strata strings.
In the case of \code{data.frame}, the logical vector of responses must be indicated as a
variable name in \code{.var}.}
\item{.var}{(\code{string})\cr single variable name that is passed by \code{rtables} when requested
by a statistics function.}
}
\value{
\itemize{
\item \code{estimate_proportion()} returns a layout object suitable for passing to further layouting functions,
or to \code{\link[rtables:build_table]{rtables::build_table()}}. Adding this function to an \code{rtable} layout will add formatted rows containing
the statistics from \code{s_proportion()} to the table layout.
}
\itemize{
\item \code{s_proportion()} returns statistics \code{n_prop} (\code{n} and proportion) and \code{prop_ci} (proportion CI) for a
given variable.
}
\itemize{
\item \code{a_proportion()} returns the corresponding list with formatted \code{\link[rtables:CellValue]{rtables::CellValue()}}.
}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}}
Estimate the proportion of responders within a studied population.
}
\section{Functions}{
\itemize{
\item \code{estimate_proportion()}: Layout-creating function which can take statistics function arguments
and additional format arguments. This function is a wrapper for \code{\link[rtables:analyze]{rtables::analyze()}}.
\item \code{s_proportion()}: Statistics function estimating a
proportion along with its confidence interval.
\item \code{a_proportion()}: Formatted analysis function which is used as \code{afun}
in \code{estimate_proportion()}.
}}
\examples{
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)
# 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"
)
}
\seealso{
\link{h_proportions}
}