Skip to content

Commit

Permalink
amending qt
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyyeoCH committed Aug 29, 2023
1 parent f0d5d00 commit b9e50b2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions R/dbetabinom.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ dbetaMix <- Vectorize(dbetaMix, vectorize.args = "x")
#' @typed lower.tail : flag
#' if `TRUE` (default), probabilities are `P[X <= x]`,
#' and otherwise `P[X > x]`.
#' @return The (one minus) cdf value # TODO DO WE NEED THIS return and where is the "1-".
#' @return The (one minus) cdf value
#'
#' @note `q` can be a vector.
#'
Expand Down Expand Up @@ -196,9 +196,9 @@ pbetaMix <- Vectorize(pbetaMix, vectorize.args = "q")
#'
#' @example examples/qbetaMix.R
#' @export
qbetaMix <- function(qt, par, weights, lower.tail = TRUE) {
qbetaMix <- function(p, par, weights, lower.tail = TRUE) {
f <- function(pi) {
pbetaMix(q = pi, par = par, weights = weights, lower.tail = lower.tail) - qt
pbetaMix(q = pi, par = par, weights = weights, lower.tail = lower.tail) - p
}
unirootResult <- uniroot(f, lower = 0, upper = 1)
if (unirootResult$iter < 0) {
Expand All @@ -208,4 +208,4 @@ qbetaMix <- function(qt, par, weights, lower.tail = TRUE) {
unirootResult$root
}
}
qbetaMix <- Vectorize(qbetaMix, vectorize.args = "qt")
qbetaMix <- Vectorize(qbetaMix, vectorize.args = "p")
6 changes: 3 additions & 3 deletions examples/qbetaMix.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## Only 1 mixture component, i.e., weights = 1
qbetaMix(
qt = 0.60,
p = 0.60,
par = rbind(c(0.2, 0.4)),
weights = 1
)

## With 2 mixture components
qbetaMix(
qt = 0.6, par = rbind(c(0.2, 0.4), c(1, 1)),
p = 0.6, par = rbind(c(0.2, 0.4), c(1, 1)),
weights = c(0.6, 0.4)
)

## Can also specify q as a vector
qbetaMix(
qt = seq(0, 1, .01),
p = seq(0, 1, .01),
par = rbind(c(0.2, 0.4), c(1, 1)),
weights = c(0.6, 0.4)
)
2 changes: 1 addition & 1 deletion man/pbetaMix.Rd

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

12 changes: 6 additions & 6 deletions man/qbetaMix.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-dbetabinom.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test_that("The complement of pbetaMix can be derived with a different lower.tail

test_that("The qbetaMix has the correct number result", {
result <- qbetaMix(
qt = 0.6,
p = 0.6,
par = rbind(c(0.2, 0.4)),
weights = 1
)
Expand All @@ -113,7 +113,7 @@ test_that("The qbetaMix has the correct number result", {

test_that("The qbetaMix has the correct number result", {
result <- qbetaMix(
qt = 0.6,
p = 0.6,
par = rbind(c(0.2, 0.4), c(1, 1)),
weights = c(0.6, 0.4)
)
Expand All @@ -122,7 +122,7 @@ test_that("The qbetaMix has the correct number result", {

test_that("The qbetaMix has a number result", {
result <- qbetaMix(
qt = seq(0, 1, .01),
p = seq(0, 1, .01),
par = rbind(c(0.2, 0.4), c(1, 1)),
weights = c(0.6, 0.4)
)
Expand Down

0 comments on commit b9e50b2

Please sign in to comment.