Skip to content

Commit b40a03b

Browse files
131 make oc preds faster (#140)
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
1 parent ba8969b commit b40a03b

12 files changed

+291
-215
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Language: en-US
5353
LazyData: true
5454
Roxygen:
5555
list(markdown = TRUE, packages = "roxytypes")
56-
RoxygenNote: 7.3.2
56+
RoxygenNote: 7.3.3
5757
Config/Needs/documentation:
5858
roxytypes
5959
Remotes:

R/dbetabinom.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ h_getBetamixPost <- function(x, n, par, weights) {
9292
postPar[, 2] <- postPar[, 2] + n - x
9393
# We compute updated mixture probabilities.
9494
tmp <- exp(
95-
lbeta(a = postPar[, 1], b = postPar[, 2]) - lbeta(a = par[, 1], b = par[, 2])
95+
lbeta(a = postPar[, 1], b = postPar[, 2]) -
96+
lbeta(a = par[, 1], b = par[, 2])
9697
)
9798
# We compute the updated weights of the posterior
9899
postWeights <- weights * tmp / sum(weights * tmp)
@@ -121,7 +122,13 @@ h_getBetamixPost <- function(x, n, par, weights) {
121122
#' @example examples/dbetaMix.R
122123
#' @export
123124
dbetaMix <- function(x, par, weights, log = FALSE) {
124-
assert_numeric(weights, lower = 0, upper = 1, finite = TRUE, any.missing = FALSE)
125+
assert_numeric(
126+
weights,
127+
lower = 0,
128+
upper = 1,
129+
finite = TRUE,
130+
any.missing = FALSE
131+
)
125132
assert_true(all.equal(sum(weights), 1))
126133
assert_true(identical(length(weights), nrow(par)))
127134
degree <- length(weights)
@@ -221,7 +228,10 @@ qbetaMix <- function(p, par, weights, lower.tail = TRUE) {
221228

222229
diff <- f_grid - p
223230
pos <- diff > 0
224-
grid_interval <- c(grid[!pos][which.max(diff[!pos])], grid[pos][which.min(diff[pos])])
231+
grid_interval <- c(
232+
grid[!pos][which.max(diff[!pos])],
233+
grid[pos][which.min(diff[pos])]
234+
)
225235

226236
uniroot(
227237
f = function(q) .pbetaMix(q, par, weights, lower.tail = lower.tail) - p,

examples/ocPredprobDist.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# - Interim look for Efficacy: Pr( success at final ) > 80%
99
# - Interim look for Futility: Pr( failure at final ) < 20%
1010
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
11-
1211
set.seed(20)
1312
result <- ocPredprobDist(
1413
nnE = c(10, 20, 30),
@@ -43,7 +42,8 @@ result$oc
4342
# - Interim look for Futility: Pr( failure at final ) < 20%
4443
# We assume a prior of treatment arm parE = Beta(1,1), unless otherwise indicated.
4544
#
46-
set.seed(20)
45+
\donttest{
46+
set.seed(20)
4747
result <- ocPredprobDist(
4848
nnE = c(10, 20, 30),
4949
truep = 0.40,
@@ -64,6 +64,7 @@ result <- ocPredprobDist(
6464
)
6565
result$oc
6666

67+
6768
# Here we illustrate an example for Decision 2 with the following assumptions :
6869
# Efficacy Looks and Futility looks are identical at sample size of 10, 20 and 30
6970
# where sample looks are allowed to wiggle.
@@ -130,3 +131,4 @@ result <- ocPredprobDist(
130131
decision1 = FALSE
131132
)
132133
result$oc
134+
}

man/ocPredprobDist.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotDecision.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/plotOc.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.

tests/testthat/_snaps/plotBetaDiff/Plot-of-plotBetaDiff-with-beta-mixture.svg

Lines changed: 91 additions & 0 deletions
Loading

tests/testthat/_snaps/plotBetaDiff/Plot-of-plotBetaDiff-without-beta-mixture.svg

Lines changed: 84 additions & 0 deletions
Loading

tests/testthat/_snaps/plotBetaDiff/plot-of-distibution-of-difference-of-two-arms-with-beta-mixture.svg

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/testthat/_snaps/plotBetaDiff/plot-of-distibution-of-difference-of-two-arms.svg

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)