Skip to content

Commit 8744ed4

Browse files
committed
clean
1 parent abe992b commit 8744ed4

File tree

4 files changed

+80
-43
lines changed

4 files changed

+80
-43
lines changed

R/betadiff.R

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' @typed eps : number
2020
#' lowest floating point number as lower bound of integration
2121
#' @typed rel.tol : number
22-
#' used in `[stats::integrate()]`
22+
#' used in [stats::integrate()]
2323
#' @return The density values
2424
#'
2525
#' @note `X` and `Y` can be either Control or Treatment and `Z = X-Y`, subject to assumptions.
@@ -28,14 +28,38 @@
2828
#' @rdname dbetadiff
2929
#' @example examples/dbetadiff.R
3030
#' @export
31-
dbetadiff <- function(z, parY, parX, eps = .Machine$double.eps, rel.tol = .Machine$double.eps^0.1) {
32-
assert_numeric(z, min.len = 1, finite = TRUE, any.missing = TRUE, null.ok = FALSE)
31+
dbetadiff <- function(
32+
z,
33+
parY,
34+
parX,
35+
eps = .Machine$double.eps,
36+
rel.tol = .Machine$double.eps^0.1
37+
) {
38+
assert_numeric(
39+
z,
40+
min.len = 1,
41+
finite = TRUE,
42+
any.missing = TRUE,
43+
null.ok = FALSE
44+
)
3345
ret <- z
3446
is_z_pos <- z >= 0
3547
is_z_neg <- z < 0
3648

37-
assert_numeric(parY, len = 2, lower = .Machine$double.xmin, any.missing = FALSE, finite = TRUE)
38-
assert_numeric(parX, len = 2, lower = .Machine$double.xmin, any.missing = FALSE, finite = TRUE)
49+
assert_numeric(
50+
parY,
51+
len = 2,
52+
lower = .Machine$double.xmin,
53+
any.missing = FALSE,
54+
finite = TRUE
55+
)
56+
assert_numeric(
57+
parX,
58+
len = 2,
59+
lower = .Machine$double.xmin,
60+
any.missing = FALSE,
61+
finite = TRUE
62+
)
3963
assert_number(eps, finite = TRUE)
4064

4165
integrandPos <- function(x, zval) {
@@ -131,7 +155,8 @@ qbetadiff <- function(p, parY, parX, eps = .Machine$double.eps) {
131155
q = q,
132156
parY = parY,
133157
parX = parX
134-
) - p
158+
) -
159+
p
135160
}
136161
eps <- 1e-10
137162
stats::uniroot(

R/ocRctPostprobDist.R

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
#' - `nActive` : mean of look size for Active arm.
1919
#' - `nControl` : mean of look size for Control arm.
2020
#' @keywords internal
21-
h_get_decisionDist_rct <- function(nnr,
22-
nnrE,
23-
nnrF,
24-
pE,
25-
pS,
26-
parE = c(1, 1),
27-
parS = c(1, 1),
28-
tL,
29-
tU,
30-
deltaE,
31-
deltaF,
32-
relativeDelta,
33-
randRatio = 1,
34-
Nmax,
35-
orig_nnr) {
21+
h_get_decisionDist_rct <- function(
22+
nnr,
23+
nnrE,
24+
nnrF,
25+
pE,
26+
pS,
27+
parE = c(1, 1),
28+
parS = c(1, 1),
29+
tL,
30+
tU,
31+
deltaE,
32+
deltaF,
33+
relativeDelta,
34+
randRatio = 1,
35+
Nmax,
36+
orig_nnr
37+
) {
3638
assert_numeric(nnr, finite = TRUE, any.missing = FALSE)
3739
assert_numeric(nnrE, max.len = length(nnr), any.missing = FALSE)
3840
assert_numeric(nnrF, max.len = length(nnr), any.missing = FALSE)
@@ -70,10 +72,10 @@ h_get_decisionDist_rct <- function(nnr,
7072

7173
if (size_look %in% nnrF) {
7274
qL <- postprobDist(
73-
xS = sum(xControl),
74-
nS = length(xControl),
75-
x = sum(xActive),
76-
n = length(xActive),
75+
x = sum(xControl),
76+
n = length(xControl),
77+
xS = sum(xActive),
78+
nS = length(xActive),
7779
delta = deltaF,
7880
relativeDelta = relativeDelta,
7981
parE = parS,
@@ -194,21 +196,29 @@ h_get_oc_rct <- function(all_sizes, Nmax, nActive, nControl, decision) {
194196
#' Response rate in Control group.
195197
#' @example examples/ocRctPostprobDist.R
196198
#' @export
197-
ocRctPostprobDist <- function(nnE,
198-
pE,
199-
pS,
200-
deltaE,
201-
deltaF,
202-
relativeDelta = FALSE,
203-
tL,
204-
tU,
205-
parE,
206-
parS,
207-
randRatio = 1,
208-
sim,
209-
wiggle = FALSE,
210-
nnF = nnE) {
211-
assert_numeric(nnE, min.len = 1, lower = 1, upper = max(nnE), any.missing = FALSE)
199+
ocRctPostprobDist <- function(
200+
nnE,
201+
pE,
202+
pS,
203+
deltaE,
204+
deltaF,
205+
relativeDelta = FALSE,
206+
tL,
207+
tU,
208+
parE,
209+
parS,
210+
randRatio = 1,
211+
sim,
212+
wiggle = FALSE,
213+
nnF = nnE
214+
) {
215+
assert_numeric(
216+
nnE,
217+
min.len = 1,
218+
lower = 1,
219+
upper = max(nnE),
220+
any.missing = FALSE
221+
)
212222
assert_number(pE, lower = 0, upper = 1)
213223
assert_number(pS, lower = 0, upper = 1)
214224
assert_number(deltaE, upper = 1, finite = TRUE)
@@ -225,7 +235,9 @@ ocRctPostprobDist <- function(nnE,
225235
if (sim < 50000) {
226236
warning("Advise to use sim >= 50000 to achieve convergence")
227237
}
228-
decision <- all_sizes <- all_looks <- nActive <- nControl <- vector(length = sim)
238+
decision <- all_sizes <- all_looks <- nActive <- nControl <- vector(
239+
length = sim
240+
)
229241
nnE <- sort(nnE)
230242
nnF <- sort(nnF)
231243
nn <- sort(unique(c(nnF, nnE)))

man/dbetadiff.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pbetadiff.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)