Skip to content

Commit 4bbc9ae

Browse files
committed
more test
1 parent b882dbf commit 4bbc9ae

File tree

7 files changed

+201
-5
lines changed

7 files changed

+201
-5
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# R specific hooks: https://github.com/lorenzwalthert/precommit
44
repos:
55
- repo: https://github.com/lorenzwalthert/precommit
6-
rev: v0.4.2
6+
rev: v0.4.3
77
hooks:
88
- id: style-files
99
args: [--style_pkg=styler, --style_fun=tidyverse_style]
@@ -91,6 +91,6 @@ repos:
9191
files: '\.Rhistory|\.RData|\.Rds|\.rds$'
9292
# `exclude: <regex>` to allow committing specific files.
9393
- repo: https://github.com/igorshubovych/markdownlint-cli
94-
rev: v0.40.0
94+
rev: v0.41.0
9595
hooks:
9696
- id: markdownlint

R/dbetabinom.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ qbetaMix <- function(p, par, weights, lower.tail = TRUE) {
229229

230230
uniroot(
231231
f = function(q) pbetaMix(q, par, weights, lower.tail = lower.tail, skipchecks = TRUE) - p,
232-
# interval = c(0, 1),
233232
interval = grid_interval,
234233
f.lower = -p,
235234
f.upper = 1 - p,

R/postprobDist.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ postprobDist <- function(x,
178178
activeBetamixPost <- lapply(x, function(x) h_getBetamixPost(x = x, n = n, par = parE, weights = weights))
179179

180180
controlBetamixPost <- h_getBetamixPost(x = xS, n = nS, par = parS, weights = weightsS)
181-
# assert_names(names(activeBetamixPost), identical.to = c("par", "weights"))
182-
# assert_names(names(controlBetamixPost), identical.to = c("par", "weights"))
183181
if (relativeDelta) {
184182
epsilon <- .Machine$double.xmin
185183
integrand <- h_integrand_relDelta

man/ocPredprob.Rd

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

tests/testthat/test-dbetabinom.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ test_that("pbetaMix gives the correct number result with beta-mixture", {
8484
expect_equal(result, 0.4768404, tolerance = 1e-5)
8585
})
8686

87+
test_that("pbetaMix works for edge cases", {
88+
result_ushape <- pbetaMix(
89+
q = c(0, 1),
90+
par = rbind(c(0.2, 0.4), c(3, .3)),
91+
weights = c(0.6, 0.4)
92+
)
93+
expect_equal(result_ushape, c(0, 1))
94+
95+
result_vshape <- pbetaMix(
96+
q = c(0, 1),
97+
par = rbind(c(9, 4), c(1, 1)),
98+
weights = c(0.6, 0.4)
99+
)
100+
expect_equal(result_vshape, c(0, 1))
101+
})
102+
103+
87104
test_that("The complement of pbetaMix can be derived with a different lower.tail flag", {
88105
result <- pbetaMix(
89106
q = 0.3,
@@ -184,6 +201,32 @@ test_that("dbetaMix gives the correct result as dbeta", {
184201
expect_equal(result, result2, tolerance = 1e-4)
185202
})
186203

204+
test_that("dbetaMix handles edge cases", {
205+
result_inf <- dbetaMix(
206+
x = c(0, 1), par = rbind(c(0.2, 0.4), c(1, 1)),
207+
weights = c(0.6, 0.4)
208+
)
209+
expect_equal(result_inf, c(Inf, Inf))
210+
211+
result_finite <- dbetaMix(
212+
x = c(0, 1), par = rbind(c(2, 4), c(1, 1)),
213+
weights = c(0.6, 0.4)
214+
)
215+
expect_equal(result_finite, c(0.4, 0.4))
216+
217+
result_right <- dbetaMix(
218+
x = c(0, 1), par = rbind(c(0, 4), c(1, 1)),
219+
weights = c(0.6, 0.4)
220+
)
221+
expect_equal(result_right, c(Inf, 0.4))
222+
223+
result_right <- dbetaMix(
224+
x = c(NA, 1), par = rbind(c(0, 4), c(1, 1)),
225+
weights = c(0.6, 0.4)
226+
)
227+
expect_equal(result_right, c(NA, 0.4))
228+
})
229+
187230
# h_getBetamixPost ----
188231

189232
test_that("h_getBetamixPost gives the correct beta-mixture parameters", {

tests/testthat/test-postprob.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,18 @@ test_that("postprob gives incrementally higher values with increased x", {
5353
)
5454
expect_true(is_lower < is_higher)
5555
})
56+
57+
test_that("postprob works with vector x", {
58+
result <- postprob(x = 0:23, n = 23, p = 0.60, par = c(0.6, 0.4))
59+
expected <- c(
60+
1.12066620085448e-10, 6.73786529927603e-09, 1.45879637562279e-07,
61+
1.86374536434781e-06, 1.64656040420248e-05, 0.000108838231763851,
62+
0.000564103325535708, 0.00236446983272442, 0.00819197194809839,
63+
0.0238449136766029, 0.0590640325657381, 0.125847456119664,
64+
0.232931221473374, 0.378259188739121, 0.54495891589689,
65+
0.705949748288983, 0.835980805221058, 0.922929283049132,
66+
0.970355725500809, 0.991009176245894, 0.997963909660055,
67+
0.999685712592687, 0.999972679748126, 0.99999934483779
68+
)
69+
expect_equal(result, expected, tolerance = 1e-5)
70+
})

tests/testthat/test-postprobDist.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ test_that("postprobDist gives the correct result for a weighted beta-mixture", {
8484
expect_equal(result, 0.3248885, tolerance = 1e-4)
8585
})
8686

87+
test_that("postprobDist works with vector x", {
88+
result <- postprobDist(
89+
x = c(0, 10, 22, 23),
90+
n = 23,
91+
delta = 0.1,
92+
parE = rbind(
93+
c(0.6, 0.4),
94+
c(1, 1)
95+
),
96+
parS = rbind(
97+
c(0.6, 0.4),
98+
c(1, 1)
99+
),
100+
weights = c(0.5, 0.5),
101+
weightsS = c(0.3, 0.7)
102+
)
103+
expected <- c(0.0022653966293937, 0.324888481243124, 0.771937234865335, 0.817017633697455)
104+
expect_equal(result, expected, tolerance = 1e-4)
105+
})
106+
87107
test_that("postprobDist gives an error when n is not a number.", {
88108
expect_error(
89109
results <- postprobDist(

0 commit comments

Comments
 (0)