Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IncrementsMaxToxProb #861

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60e416b
Implement IncrementsMaxToxProb
Puzzled-Face Sep 20, 2024
3db5599
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 20, 2024
4d3a179
Fix lintr errors
Puzzled-Face Sep 20, 2024
2df024e
Merge branch '860-create-an-increments-rule-based-on-limiting-the-pro…
Puzzled-Face Sep 20, 2024
15fa563
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 20, 2024
b51b8c5
Use seq-alone correctly
Puzzled-Face Sep 23, 2024
8fd5879
Merge branch '860-create-an-increments-rule-based-on-limiting-the-pro…
Puzzled-Face Sep 23, 2024
c4477bd
Fix documentation
Puzzled-Face Sep 23, 2024
6a996c6
Update R/Rules-validity.R
Puzzled-Face Sep 23, 2024
b1789e1
Update R/Rules-methods.R
Puzzled-Face Sep 23, 2024
cee9342
Update R/Rules-methods.R
Puzzled-Face Sep 23, 2024
2afe296
Refactor as per reviewer request. Additional unit tests.
Puzzled-Face Sep 23, 2024
f453f9a
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 23, 2024
c1bf1bf
Respond to reviewer comments. Fix pkgdown errors.
Puzzled-Face Sep 24, 2024
c13af55
Merge branch '860-create-an-increments-rule-based-on-limiting-the-pro…
Puzzled-Face Sep 24, 2024
de9a932
Fix documentation error
Puzzled-Face Sep 24, 2024
82030cc
Merge branch 'main' into 860-create-an-increments-rule-based-on-limit…
Puzzled-Face Sep 30, 2024
3aa8100
Merge branch 'main' into 860-create-an-increments-rule-based-on-limit…
Puzzled-Face Sep 30, 2024
d52edc2
Fix R CMD Check warning
Puzzled-Face Sep 30, 2024
f4c8e03
Merge branch '860-create-an-increments-rule-based-on-limiting-the-pro…
Puzzled-Face Sep 30, 2024
417c9a5
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 30, 2024
31cfb0b
Update R/Rules-methods.R
Puzzled-Face Oct 7, 2024
9e3f83e
Merge branch 'main' into 860-create-an-increments-rule-based-on-limit…
Puzzled-Face Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export(.DefaultGeneralSimulationsSummary)
export(.DefaultIncrements)
export(.DefaultIncrementsDoseLevels)
export(.DefaultIncrementsHSRBeta)
export(.DefaultIncrementsMaxToxProb)
export(.DefaultIncrementsMin)
export(.DefaultIncrementsOrdinal)
export(.DefaultIncrementsRelative)
Expand Down Expand Up @@ -239,6 +240,7 @@ export(.GeneralSimulations)
export(.GeneralSimulationsSummary)
export(.IncrementsDoseLevels)
export(.IncrementsHSRBeta)
export(.IncrementsMaxToxProb)
export(.IncrementsMin)
export(.IncrementsOrdinal)
export(.IncrementsRelative)
Expand Down Expand Up @@ -348,6 +350,7 @@ export(FractionalCRM)
export(GeneralSimulations)
export(IncrementsDoseLevels)
export(IncrementsHSRBeta)
export(IncrementsMaxToxProb)
export(IncrementsMin)
export(IncrementsOrdinal)
export(IncrementsRelative)
Expand Down Expand Up @@ -558,6 +561,7 @@ exportClasses(GeneralSimulationsSummary)
exportClasses(Increments)
exportClasses(IncrementsDoseLevels)
exportClasses(IncrementsHSRBeta)
exportClasses(IncrementsMaxToxProb)
exportClasses(IncrementsMin)
exportClasses(IncrementsOrdinal)
exportClasses(IncrementsRelative)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version 2.0.0.9158
* **Note: This release (1.0 -> 2.0) signifies a major breaking revamp of the package.** Users are advised to carefully review the release notes and documentation for detailed information on the changes and any necessary updates to their existing code.
* Implemented the `IncrementsMaxToxProb` class
* Implemented `knit_print` methods for almost all `crmPack` classes to improve rendering in Markdown and Quarto documents. See the vignette for more details.
* Provided basic support for ordinal CRM models. See the vignette for more details.
* Implemented `broom`-like `tidy` methods for all concrete `crmPack` classes. See the vignette for more details.
Expand Down
59 changes: 59 additions & 0 deletions R/Rules-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,65 @@ IncrementsOrdinal <- function(grade, rule) {
)
}

# IncrementsMaxToxProb ----

## class ----

#' `IncrementsMaxToxProb`
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' [`IncrementsMaxToxProb`] is the class for increments control based on
#' probability of toxicity
#'
#' @slot prob (`numeric`)\cr See Usage Notes below.
#'
#' @section Usage Notes:
#' For binary models, `prob` should be a scalar probability.
#'
#' For ordinal models, `prob` should be a named vector containing the maximum
#' permissible probability of toxicity by grade. The names should match the
#' names of the `yCategories` slot of the associated `DataOrdinal` object.
#'
#' @aliases IncrementsMaxToxProb
#' @export
#'
.IncrementsMaxToxProb <- setClass(
Class = "IncrementsMaxToxProb",
slots = c(
prob = "numeric"
),
prototype = prototype(
prob = c("DLAE" = 0.2, "DLT" = 0.05)
),
contains = "Increments",
validity = v_increments_maxtoxprob
)

## constructor ----

#' @rdname IncrementsMaxToxProb-class
#'
#' @param prob (`numeric`)\cr see slot definition.
#'
#' @export
#' @example examples/Rules-class-IncrementsMaxToxProb.R
#'
IncrementsMaxToxProb <- function(prob) {
.IncrementsMaxToxProb(
prob = prob
)
}

## default constructor ----

#' @rdname IncrementsMaxToxProb-class
#' @note Typically, end users will not use the `.DefaultIncrementsMaxToxProb()` function.
#' @export
.DefaultIncrementsMaxToxProb <- function() {
IncrementsMaxToxProb(prob = c("DLAE" = 0.2, "DLT" = 0.05))
}

# Stopping ----

## class ----
Expand Down
86 changes: 86 additions & 0 deletions R/Rules-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,92 @@ setMethod(
}
)

## IncrementsMaxToxProb ----

#' @describeIn maxDose determine the maximum possible next dose based on the
#' probability of toxicity
#' @param model (`GeneralModel`)\cr The model on which probabilities will be based
#' @param `samples` (`Samples`)\cr The MCMC samples to which `model` will be applied
#'
#' @aliases maxDose-IncrementsMaxToxProb
#'
#' @export
#' @example examples/Rules-method-maxDose-IncrementsMaxToxProb.R
#'
setMethod(
f = "maxDose",
signature = signature(
increments = "IncrementsMaxToxProb",
data = "DataOrdinal"
),
definition = function(increments, data, model, samples, ...) {
assert_class(samples, "Samples")
assert_true(length(increments@prob) == length(data@yCategories) - 1)
nm <- names(data@yCategories)[2:length(data@yCategories)]
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
assert_set_equal(names(increments@prob), nm)

probs <- lapply(
seq_along(increments@prob),
function(g) {
fit(samples, model, data, grade = g, ...) %>%
dplyr::filter(middle < increments@prob[nm[g]]) %>%
utils::tail(1)
}
) %>%
dplyr::bind_rows()
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
return(min(probs$dose))
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
}
)
#' @describeIn maxDose determine the maximum possible next dose based on the
#' probability of toxicity
#' @param model (`GeneralModel`)\cr The model on which probabilities will be based
#' @param samples (`Samples`)\cr The MCMC samples to which `model` will be applied
#'
#' @aliases maxDose-IncrementsMaxToxProb
#'
#' @export
#' @example examples/Rules-method-maxDose-IncrementsMaxToxProb.R
#'
setMethod(
f = "maxDose",
signature = signature(
increments = "IncrementsMaxToxProb",
data = "Data"
),
definition = function(increments, data, model, samples, ...) {
assert_class(samples, "Samples")
assert_true(length(increments@prob) == 1)

prob <- fit(samples, model, data, ...) %>%
dplyr::filter(middle < increments@prob) %>%
utils::tail(1) %>%
dplyr::pull(dose)
return(prob)
}
)

## tidy-IncrementsMaxToxProb ----

#' @rdname tidy
#' @aliases tidy-IncrementsMaxToxProb
#' @example examples/Rules-method-tidyIncrementsMaxToxProb.R
#' @export
setMethod(
f = "tidy",
signature = signature(x = "IncrementsMaxToxProb"),
definition = function(x, ...) {
grades <- names(x@prob)
if (is.null(grades)) {
grades <- "1"
}
tibble(
Grade = grades,
Prob = x@prob
) %>%
crmPack:::h_tidy_class(x)
}
)

# nolint start

## ============================================================
Expand Down
14 changes: 14 additions & 0 deletions R/Rules-validity.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ v_increments_min <- function(object) {
v$result()
}

#' @describeIn v_increments validates the [`IncrementsMaxToxProb`]
v_increments_maxtoxprob <- function(object) {
v <- crmPack:::Validate()
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
v$check(
test_probabilities(object@prob),
"prob must be a vector of probabilities with minimum length 1 and no missing values"
)
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
v$check(
test_numeric(object@prob, any.missing = FALSE, min.len = 1),
"prob must be a vector of probabilities with minimum length 1 and no missing values"
)
v$result()
}

# Stopping ----

#' Internal Helper Functions for Validation of [`Stopping`] Objects
Expand Down
5 changes: 5 additions & 0 deletions examples/Rules-class-IncrementsMaxToxProb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# For use with binary models and data
IncrementsMaxToxProb(prob = 0.35)

# For use with ordinal models and data
IncrementsMaxToxProb(prob = c("DLAE" = 0.2, "DLT" = 0.05))
17 changes: 17 additions & 0 deletions examples/Rules-method-maxDose-IncrementsMaxToxProb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
model <- LogisticLogNormalOrdinal(
mean = c(0.25, 0.15, 0.5),
cov = matrix(c(1.5, 0, 0, 0, 2, 0, 0, 0, 1), nrow = 3),
ref_dose = 30
)

emptyData <- DataOrdinal(
doseGrid = c(1, 3, 9, 25, 50, 75, 100),
yCategories = c("No tox" = 0L, "DLAE" = 1L, "CRS" = 2L)
)

# For warning regarding tox, see issue #748 https://github.com/openpharma/crmPack/issues/748
Puzzled-Face marked this conversation as resolved.
Show resolved Hide resolved
suppressWarnings({
samples <- mcmc(emptyData, model, .DefaultMcmcOptions())
})
toxIncrements <- IncrementsMaxToxProb(probs = c("DLAE" = 0.2, "CRS" = 0.05))
maxDose(toxIncrements, emptyData, model, samples)
1 change: 1 addition & 0 deletions examples/Rules-method-tidyIncrementsMaxToxProb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IncrementsMaxToxProb(prob = c("DLAE" = 0.2, "CRS" = 0.05)) %>% tidy()
48 changes: 48 additions & 0 deletions man/IncrementsMaxToxProb-class.Rd

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

2 changes: 1 addition & 1 deletion man/crmPackExample.Rd

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

2 changes: 1 addition & 1 deletion man/crmPackHelp.Rd

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

53 changes: 53 additions & 0 deletions man/maxDose.Rd

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

Loading
Loading