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

New commit for additional statistics #663

Merged
merged 32 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
02e6855
New commit for additional statistics
Prerana17 Aug 16, 2023
94c076f
Merge 02e685556ccd1e12becd15155c4188def6d45f24 into 23982ded06130d207…
Prerana17 Aug 16, 2023
f4280f9
[skip actions] Restyle files
github-actions[bot] Aug 16, 2023
96ea829
Update: additional statstics added to other designs bug correction su…
Prerana17 Aug 17, 2023
ebfd762
bug corrected
ClaraBeckBayer Aug 17, 2023
2741f9a
Update: Additional_stats
Prerana17 Aug 18, 2023
cfccb61
update: additional_stats
Prerana17 Aug 18, 2023
6dc58eb
updaze: error_corrections (additional_stats)
Prerana17 Aug 18, 2023
e24202b
update: additional_statistics
Prerana17 Aug 21, 2023
7a94c59
Dynamic: Additional_statistical_summary
Prerana17 Aug 30, 2023
27d41e3
Additional statistical summary function update
Prerana17 Aug 31, 2023
c329a82
additional statistical summary changes
Prerana17 Aug 31, 2023
4940312
Update: Additional Statistical Summary
Prerana17 Sep 1, 2023
2ff5275
small change: additional stat summary
Prerana17 Sep 1, 2023
969b530
Merge branch 'main' into 656_additional_stat
0liver0815 Sep 1, 2023
bea2537
Suggested changes: additional_statistics and validation
Prerana17 Sep 14, 2023
1ec6575
Merge bea25375ae19e5b5694853af2cda9c8cec7fe27b into 1762da78c4b3aeaa6…
Prerana17 Sep 14, 2023
1e424d9
[skip actions] Restyle files
github-actions[bot] Sep 14, 2023
24a3591
Merge branch 'main' into 656_additional_stat
0liver0815 Sep 18, 2023
8e06ac3
Simulation refectoring
Prerana17 Sep 28, 2023
ec070be
Simulation small update
Prerana17 Oct 6, 2023
fac045c
Merge branch 'main' into 656_additional_stat
Prerana17 Oct 9, 2023
a6a2ca9
Merge fac045c5a79e581d0e4d4062fb8765f661bafa24 into d6d5434713e696c23…
Prerana17 Oct 9, 2023
53955f8
[skip actions] Restyle files
github-actions[bot] Oct 9, 2023
ecfcff5
small update
Prerana17 Oct 9, 2023
b9e7ca5
Merge branch '656_additional_stat' of https://github.com/Roche/crmPac…
Prerana17 Oct 9, 2023
7b113d2
incorrectly named file:delete
Prerana17 Oct 9, 2023
232c94a
removing documentation errors
Prerana17 Oct 9, 2023
97e309a
update yaml file
Prerana17 Oct 10, 2023
7192f55
Merge branch 'main' into 656_additional_stat
Prerana17 Oct 10, 2023
4717780
Merge branch 'main' into 656_additional_stat
Prerana17 Oct 10, 2023
9cdeabe
Merge branch 'main' into 656_additional_stat
danielinteractive Oct 11, 2023
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
24 changes: 23 additions & 1 deletion R/Design-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,19 @@ setMethod("simulate",
data = thisData
)

# Get the MTD estimate from the samples.
sample_mtd <- dose(
mean(object@nextBest@target),
model = object@model,
samples = thisSamples
)
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved

# Create list with median MTD and CV.
additional_stats <- list(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice I think, however I wonder if we can make this more flexible for the user - e.g. how about accepting a list of functions as part of the simulate() call and then the user can define median, cv functions etc. to apply to target_dose_samples?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great proposal. I really like that idea. This will add much flexibility e.g. if someone want to see the mean instead of the median etc.. We just have to evaluate, if it is straight forward to implement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielinteractive @0liver0815 Sure, as the next step, I will try to implement the functions where user can define median, cv, mean etc. functions.

median_mtd = median(sample_mtd),
cv_mtd = mad(sample_mtd) / median(sample_mtd)
)

## return the results
thisResult <-
list(
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -431,7 +444,8 @@ setMethod("simulate",
stopit,
"message"
),
report_results = stopit_results
report_results = stopit_results,
additional_stats = additional_stats
)
return(thisResult)
}
Expand Down Expand Up @@ -470,13 +484,17 @@ setMethod("simulate",
stopResults <- lapply(resultList, "[[", "report_results")
stop_matrix <- as.matrix(do.call(rbind, stopResults))

# Result list of additional stats such as median MTD and mean CV MTD values.
additional_stats <- lapply(resultList, "[[", "additional_stats")

## return the results in the Simulations class object
ret <- Simulations(
data = dataList,
doses = recommendedDoses,
fit = fitList,
stop_report = stop_matrix,
stop_reasons = stopReasons,
additional_stats = additional_stats,
seed = RNGstate
)

Expand Down Expand Up @@ -1075,6 +1093,9 @@ setMethod("simulate",
## for dual simulations as it would fail in summary otherwise (for dual simulations reporting is not implemented)
stop_report <- matrix(TRUE, nrow = nsim)

## For dual simulations summary of additional statistics like median MTD and mean CV MTD
additional_stats <- vector(mode = "list", length = nsim)

## return the results in the DualSimulations class object
ret <- DualSimulations(
data = dataList,
Expand All @@ -1085,6 +1106,7 @@ setMethod("simulate",
fit_biomarker = fitBiomarkerList,
stop_report = stop_report,
stop_reasons = stopReasons,
additional_stats = additional_stats,
seed = RNGstate
)

Expand Down
20 changes: 17 additions & 3 deletions R/Simulations-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ GeneralSimulations <- function(data,
#' @slot fit (`list`)\cr final fits
#' @slot stop_reasons (`list`)\cr stopping reasons for each simulation run
#' @slot stop_report matrix of stopping rule outcomes
#' @slot additional_stats list of median MTD and mean CV MTD values
#' @aliases Simulations
#' @export
.Simulations <-
Expand All @@ -115,7 +116,8 @@ GeneralSimulations <- function(data,
slots = c(
fit = "list",
stop_report = "matrix",
stop_reasons = "list"
stop_reasons = "list",
additional_stats = "list"
),
prototype = prototype(
fit =
Expand All @@ -125,7 +127,9 @@ GeneralSimulations <- function(data,
),
stop_report = matrix(TRUE, nrow = 2),
stop_reasons =
list("A", "A")
list("A", "A"),
additional_stats =
list(1, 0.4)
),
contains = "GeneralSimulations",
validity =
Expand Down Expand Up @@ -153,6 +157,12 @@ GeneralSimulations <- function(data,
"stop_report must be a matrix of mode logical in which the number of rows equals the number of simulations
and which must not contain any missing values"
)

o$check(
identical(length(object@additional_stats), nSims),
"additional_stats must have same length as data"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also check that it has names?


o$result()
}
)
Expand All @@ -164,19 +174,22 @@ GeneralSimulations <- function(data,
#' @param fit (`list`)\cr see slot definition.
#' @param stop_reasons (`list`)\cr see slot definition.
#' @param stop_report see [`Simulations`]
#' @param additional_stats (`list`)\cr see slot definition.
#' @param \dots additional parameters from [`GeneralSimulations`]
#'
#' @example examples/Simulations-class-Simulations.R
#' @export
Simulations <- function(fit,
stop_reasons,
stop_report,
additional_stats,
...) {
start <- GeneralSimulations(...)
.Simulations(start,
fit = fit,
stop_report = stop_report,
stop_reasons = stop_reasons
stop_reasons = stop_reasons,
additional_stats = additional_stats
)
}

Expand Down Expand Up @@ -331,6 +344,7 @@ DualSimulations <- function(rho_est,
representation(
stop_report = "matrix",
fitAtDoseMostSelected = "numeric",
additional_stats = "list",
meanFit = "list"
),
contains = "GeneralSimulationsSummary"
Expand Down
12 changes: 12 additions & 0 deletions R/Simulations-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ setMethod("summary",
ret <- .SimulationsSummary(
start,
stop_report = object@stop_report,
additional_stats = object@additional_stats,
fitAtDoseMostSelected = fitAtDoseMostSelected,
meanFit = meanFit
)
Expand Down Expand Up @@ -985,6 +986,17 @@ setMethod("show",
"Fitted toxicity rate at dose most often selected"
)

# Report results of additional statistics such as median MTD and mean CV MTD

cat(
"Median MTD : ",
round(unlist(additional_stats)[1], 2), "\n"
)

cat(
"Mean CV (MTD) [%] : ",
round(unlist(additional_stats)[2] * 100, 2), "\n"
)

# Report individual stopping rules with non-<NA> labels.

Expand Down
6 changes: 5 additions & 1 deletion man/Simulations-class.Rd

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

6 changes: 3 additions & 3 deletions man/plotGain.Rd

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

34 changes: 34 additions & 0 deletions tests/testthat/test-Design-methods.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# simulate ----

test_that("Test if simulate generate the expected output.", {
data <- h_get_data(placebo = FALSE)
model <- h_get_logistic_normal()
increments <- h_increments_relative()
next_best <- h_next_best_ncrm()
size <- CohortSizeConst(size = 3)

# Extreme truth function, which has constant probability 1 in dose grid range.
truth <- probFunction(model, alpha0 = 175, alpha1 = 5)
stop_rule <- StoppingMinPatients(nPatients = 5)
design <- Design(
model = model,
stopping = stop_rule,
increments = increments,
nextBest = next_best,
cohort_size = size,
data = data,
startingDose = 25
)

my_options <- McmcOptions(burnin = 100, step = 2, samples = 5, rng_kind = "Mersenne-Twister", rng_seed = 3)

sim <- simulate(
design,
nsim = 1,
truth = truth,
seed = 819,
mcmcOptions = my_options
)

expect_snapshot(sim)
})


## NextBestInfTheory ----

test_that("NextBestInfTheory produces consistent results for empty data", {
Expand Down