Skip to content

Commit

Permalink
Add tests and example of pred for binomProbs()
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Oct 5, 2023
1 parent fbdf131 commit 52fc577
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
1 change: 0 additions & 1 deletion R/confint.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ confint.rxSolve <- function(object, parm = NULL, level = 0.95, ...) {
} else {
.ret <- .ret[, list(p1 = .p,
eff = stats::quantile(.SD$value, probs = .p, na.rm = TRUE)), by = c("id", "time", "trt", .by)]

}
.ret <- .ret[, setNames(as.list(stats::quantile(.SD$eff, probs = .p2, na.rm = TRUE)),
sprintf("p%s", .p2 * 100)),
Expand Down
7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,14 @@ meanProbs.default <- function(x, probs=seq(0, 1, 0.25), na.rm=FALSE,
#' https://doi.org/10.1016/j.jspi.2019.07.001.
#' @examples
#'
#' quantile(x<- rbinom(7001, p=0.375, size=1))
#' x<- rbinom(7001, p=0.375, size=1)
#' binomProbs(x)
#'
#' # you can also use the prediction interval
#' \donttest{
#' binomProbs(x, pred=TRUE)
#' }
#'
#' # Can get some extra statistics if you request onlyProbs=FALSE
#' binomProbs(x, onlyProbs=FALSE)
#'
Expand Down
26 changes: 21 additions & 5 deletions man/binomProbs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions tests/testthat/test-binomProb.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,6 @@ test_that("test binomProb()", {
expect_equal(binomProbs(x, method="ac"), t1)


f <- function(theta, w, n, Y, U) {
w * pbeta(1 - theta, n - Y + 1, Y) +
(1 - w) * pbeta(1 - theta, n - Y, Y + 1) - U
}

m <- 7
n <- 7
Y <- 3
#M <- 1000000
m <- 1000
c <- vector()
for (i in 1:M) {
w <- runif(1, 0, 1)
U <- runif(1, 0, 1)
V <- runif(1, 0, 1)
root1 <- uniroot(f, c(0, 1), w=w, n=n, Y=Y, U=U)$root
d <- qbinom(V, m, root1)
c <- c(c, d)
}
LIM <- quantile(c, c(0.05, 0.95))
expect_equal(names(binomProbs(x, pred=TRUE)), names(binomProbs(x)))

})

0 comments on commit 52fc577

Please sign in to comment.