diff --git a/R/confint.R b/R/confint.R index 7719b9404..d5fa45c68 100644 --- a/R/confint.R +++ b/R/confint.R @@ -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)), diff --git a/R/utils.R b/R/utils.R index 938199c34..526d25d56 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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) #' diff --git a/man/binomProbs.Rd b/man/binomProbs.Rd index 09e5b2bc8..d142bc644 100644 --- a/man/binomProbs.Rd +++ b/man/binomProbs.Rd @@ -14,7 +14,12 @@ binomProbs(x, ...) names = TRUE, onlyProbs = TRUE, n = 0L, - method = c("wilson", "wilsonCorrect", "agrestiCoull", "wald") + m = 0L, + pred = FALSE, + piMethod = c("lim"), + M = 5e+05, + tol = .Machine$double.eps^0.25, + ciMethod = c("wilson", "wilsonCorrect", "agrestiCoull", "wald", "wc", "ac") ) } \arguments{ @@ -45,12 +50,18 @@ number of non-\code{NA} observations. When calculating the prediction interval, this represents the number of observations used in the input ("true") distribution.} -\item{method}{gives the method for calculating the confidence +\item{piMethod}{gives the prediction interval method (currently only lim) from Lu 2020} + +\item{M}{number of simulations to run for the LIM PI.} + +\item{tol}{tolerance of root finding in the LIM prediction interval} + +\item{ciMethod}{gives the method for calculating the confidence interval. Can be: \itemize{ -\item "argestiCoull" -- Agresti-Coull method. For a 95\\% confidence +\item "argestiCoull" or "ac" -- Agresti-Coull method. For a 95\\% confidence interval, this method does not use the concept of "adding 2 successes and 2 failures," but rather uses the formulas explicitly described in the following link: @@ -59,7 +70,7 @@ described in the following link: https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Agresti-Coull_Interval. \itemize{ \item "wilson" -- Wilson Method -\item "wilsonCorrect" -- Wilson method with continuity correction +\item "wilsonCorrect" or "wc" -- Wilson method with continuity correction \item "wald" -- Wald confidence interval or standard z approximation. }} } @@ -81,9 +92,14 @@ It is used for confidence intervals with rxode2 solved objects using } \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) diff --git a/man/reexports.Rd b/man/reexports.Rd index 365c14ab7..f1310e9e9 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -82,4 +82,3 @@ below to see their documentation. \item{rxode2random}{\code{\link[rxode2random:dot-cbindOme]{.cbindOme}}, \code{\link[rxode2random:dot-expandPars]{.expandPars}}, \code{\link[rxode2random:dot-vecDf]{.vecDf}}, \code{\link[rxode2random]{cvPost}}, \code{\link[rxode2random]{invWR1d}}, \code{\link[rxode2random]{phi}}, \code{\link[rxode2random]{rinvchisq}}, \code{\link[rxode2random]{rLKJ1}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxRmvn}}, \code{\link[rxode2random]{rxSeedEng}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random:rxWithSeed]{rxWithPreserveSeed}}, \code{\link[rxode2random]{rxWithSeed}}, \code{\link[rxode2random]{rxWithSeed}}} }} -\value{ Inherited from parent routine } diff --git a/tests/testthat/test-binomProb.R b/tests/testthat/test-binomProb.R index f8ed9eb81..3a2b375d4 100644 --- a/tests/testthat/test-binomProb.R +++ b/tests/testthat/test-binomProb.R @@ -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))) })