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 1 commit
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
41 changes: 25 additions & 16 deletions R/Design-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ setMethod("simulate",
truth, args = NULL, firstSeparate = FALSE,
mcmcOptions = McmcOptions(),
parallel = FALSE, nCores =
min(parallel::detectCores(), 5),
min(parallel::detectCores(), 5), derive = NULL,
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
...) {
nsim <- safeInteger(nsim)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please assert derive properties here (list, named, unique names, elements are functions) using checkmate package functions


Expand Down Expand Up @@ -418,17 +418,20 @@ setMethod("simulate",
)

# Get the MTD estimate from the samples.

target_dose_samples <- dose(
mean(object@nextBest@target),
model = object@model,
samples = thisSamples
)

# Create list with median MTD and CV.
additional_stats <- list(
median_mtd = median(target_dose_samples),
cv_mtd = mad(target_dose_samples) / median(target_dose_samples)
)
# Create a function for additional statistical summary.
if (is.null(derive)) {
additional_stats <- list()
} else {
additional_stats <- lapply(derive, function(f) f(target_dose_samples))
}
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

@0liver0815 0liver0815 Aug 30, 2023

Choose a reason for hiding this comment

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

If default is an empty list, I think you can get rid of the if statement

Suggested change
if (is.null(derive)) {
additional_stats <- list()
} else {
additional_stats <- lapply(derive, function(f) f(target_dose_samples))
}
additional_stats <- lapply(derive, function(f) f(target_dose_samples))



## return the results
thisResult <-
Expand Down Expand Up @@ -484,7 +487,7 @@ 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.
# Result list of additional statistical summary.
additional_stats <- lapply(resultList, "[[", "additional_stats")

## return the results in the Simulations class object
Expand Down Expand Up @@ -1020,17 +1023,19 @@ setMethod("simulate",
)

# Get the MTD estimate from the samples.

target_dose_samples <- dose(
mean(object@nextBest@target),
model = object@model,
samples = thisSamples
)

# Create list with median MTD and CV.
additional_stats <- list(
median_mtd = median(target_dose_samples),
cv_mtd = mad(target_dose_samples) / median(target_dose_samples)
)
# Create a function for additional statistical summary.
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

if (is.null(derive)) {
additional_stats <- list()
} else {
additional_stats <- lapply(derive, function(f) f(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.

I think it is the same here. lapply works with an empty list.

Suggested change
if (is.null(derive)) {
additional_stats <- list()
} else {
additional_stats <- lapply(derive, function(f) f(target_dose_samples))
}
additional_stats <- lapply(derive, function(f) f(target_dose_samples))


## return the results
thisResult <-
Expand Down Expand Up @@ -4672,16 +4677,20 @@ setMethod("simulate",
data = thisData
)

# Get the MTD estimate from the samples.

target_dose_samples <- dose(
mean(object@nextBest@target),
model = object@model,
samples = thisSamples
)

additional_stats <- list(
median_mtd = median(target_dose_samples),
cv_mtd = mad(target_dose_samples) / median(target_dose_samples)
)
# Create a function for additional statistical summary.
if (is.null(derive)) {
additional_stats <- list()
} else {
additional_stats <- lapply(derive, function(f) f(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.

Same here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you need to add derive = list()to the function as done in line 212 above.


## return the results
thisResult <-
Expand Down
8 changes: 4 additions & 4 deletions R/Simulations-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +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
#' @slot additional_stats list of addtional statistical summary
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
#' @aliases Simulations
#' @export
.Simulations <-
Expand All @@ -129,7 +129,7 @@ GeneralSimulations <- function(data,
stop_reasons =
list("A", "A"),
additional_stats =
list(1, 0.4)
list(1, 1)
),
contains = "GeneralSimulations",
validity =
Expand Down Expand Up @@ -160,7 +160,7 @@ GeneralSimulations <- function(data,

o$check(
identical(length(object@additional_stats), nSims),
"additional_stats must have same length as data"
"additional_stats must have same length as the number of simulations"
)
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 Down Expand Up @@ -332,7 +332,7 @@ DualSimulations <- function(rho_est,
##' initialization function is provided for this class.
##'
##' @slot stop_report matrix of stopping rule outcomes
##' @slot additional_stats list of median MTD and mean CV MTD values
##' @slot additional_stats list of additional statistical summary
##' @slot fitAtDoseMostSelected fitted toxicity rate at dose most often selected
##' @slot meanFit list with the average, lower (2.5%) and upper (97.5%)
##' quantiles of the mean fitted toxicity at each dose level
Expand Down
21 changes: 9 additions & 12 deletions R/Simulations-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ setMethod("summary",
}
)


##' Summarize the dual-endpoint design simulations, relative to given true
##' dose-toxicity and dose-biomarker curves
##'
Expand Down Expand Up @@ -978,25 +977,23 @@ setMethod("show",
)




## add one reporting line
r$report(
"fitAtDoseMostSelected",
"Fitted toxicity rate at dose most often selected"
)

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

cat(
"Median MTD : ",
round(unlist(object@additional_stats)[1], 2), "\n"
)
if (length(list()) > 0) {
summary_stat_op <- unlist(object@additional_stats)

cat(
"Results of Additional Statistical Calculation : \n",
paste(names(summary_stat_op), ":", round(summary_stat_op), "\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok as a first version, just wondering if we should follow up in another PR to make this printing more flexible

)
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/Simulations-class-DualSimulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stop_report <- matrix(c(TRUE, FALSE), nrow = 2)

stop_reasons <- list("A", "B")

additional_stats <- list(1, 0.4)
additional_stats <- list(1, 1)

dual_simulations_obj <- DualSimulations(
rho_est = c(0.25, 0.35),
Expand Down
2 changes: 1 addition & 1 deletion examples/Simulations-class-Simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stop_report <- matrix(c(TRUE, FALSE), nrow = 2)

stop_reasons <- list("A", "B")

additional_stats <- list(1, 0.4)
additional_stats <- list(1, 1)

simulations <- Simulations(
fit = fit,
Expand Down
13 changes: 12 additions & 1 deletion examples/Simulations-method-summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ time <- system.time(mySims <- simulate(design,
nsim = 1,
seed = 819,
mcmcOptions = options,
parallel = FALSE
parallel = FALSE,
derive = list(
"max_mtd" = function(x) {
max(x)
},
"mean_mtd" = function(y) {
mean(y)
},
"median_mtd" = function(z) {
median(z)
}
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
),
))[3]

# Summarize the Results of the Simulations
Expand Down
2 changes: 1 addition & 1 deletion man/DualSimulations-class.Rd

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

4 changes: 2 additions & 2 deletions man/Simulations-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/SimulationsSummary-class.Rd

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

1 change: 1 addition & 0 deletions man/simulate-Design-method.Rd

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

13 changes: 12 additions & 1 deletion man/summary-Simulations-method.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-Simulations-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test_that("Simulations object can be created with the user constructor", {

stop_report <- matrix(c(TRUE, FALSE), nrow = 2)

additional_stats <- list(1, 0.4)
additional_stats <- list(1, 1)

data <- list(
Data(
Expand Down Expand Up @@ -151,7 +151,7 @@ test_that("DualSimulations object can be created with the user constructor", {

stop_reasons <- list("A", "B")

additional_stats <- list(1, 0.4)
additional_stats <- list(1, 1)

result <- expect_silent(
DualSimulations(
Expand Down