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 15 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
74 changes: 69 additions & 5 deletions R/Design-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ getResultList <- function(fun,
##' @param nCores how many cores should be used for parallel computing?
##' Defaults to the number of cores on the machine, maximum 5.
##' @param \dots not used
##' @param derive a list of functions which derives statistics, based on the
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
##' vector of posterior MTD samples. Each list element must therefore accept
##' one and only one argument, which is a numeric vector, and return a number.
##'
##' @return an object of class \code{\linkS4class{Simulations}}
##'
Expand All @@ -209,7 +212,7 @@ setMethod("simulate",
truth, args = NULL, firstSeparate = FALSE,
mcmcOptions = McmcOptions(),
parallel = FALSE, nCores =
min(parallel::detectCores(), 5),
min(parallel::detectCores(), 5), derive = list(),
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 @@ -417,6 +420,18 @@ setMethod("simulate",
data = thisData
)

# Get the MTD estimate from the samples.

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

# Create a function for additional statistical summary.

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.

Suggested change
additional_stats <- lapply(derive, function(f) f(target_dose_samples))
additional_stats <- lapply(derive, f, target_dose_samples)

should work too I guess?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's throwing error. So I kept same.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep makes sense actually


## return the results
thisResult <-
list(
Prerana17 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -431,7 +446,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 +486,17 @@ setMethod("simulate",
stopResults <- lapply(resultList, "[[", "report_results")
stop_matrix <- as.matrix(do.call(rbind, stopResults))

# Result list of additional statistical summary.
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 @@ -688,6 +708,9 @@ setMethod("simulate",
##' @param nCores how many cores should be used for parallel computing?
##' Defaults to the number of cores on the machine, maximum 5.
##' @param \dots not used
##' @param derive a list of functions which derives statistics, based on the
##' vector of posterior MTD samples. Each list element must therefore accept
##' one and only one argument, which is a numeric vector, and return a number.
##'
##' @return an object of class \code{\linkS4class{DualSimulations}}
##'
Expand All @@ -706,7 +729,7 @@ setMethod("simulate",
mcmcOptions = McmcOptions(),
parallel = FALSE,
nCores =
min(parallel::detectCores(), 5),
min(parallel::detectCores(), 5), derive = list(),
...) {
nsim <- safeInteger(nsim)

Expand Down Expand Up @@ -1001,6 +1024,19 @@ setMethod("simulate",
data = thisData
)

# Get the MTD estimate from the samples.

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

# 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


additional_stats <- lapply(derive, function(f) f(target_dose_samples))


## return the results
thisResult <-
list(
Expand All @@ -1025,7 +1061,8 @@ setMethod("simulate",
attr(
stopit,
"message"
)
),
additional_stats = additional_stats
)

return(thisResult)
Expand Down Expand Up @@ -1075,6 +1112,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.
additional_stats <- lapply(resultList, "[[", "additional_stats")

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

Expand Down Expand Up @@ -4142,6 +4183,9 @@ setMethod("simulate",
##' @param nCores how many cores should be used for parallel computing?
##' Defaults to the number of cores on the machine (maximum 5)
##' @param \dots not used
##' @param derive a list of functions which derives statistics, based on the
##' vector of posterior MTD samples. Each list element must therefore accept
##' one and only one argument, which is a numeric vector, and return a number.
##'
##' @return an object of class \code{\linkS4class{Simulations}}
##'
Expand All @@ -4162,6 +4206,7 @@ setMethod("simulate",
mcmcOptions = McmcOptions(),
DA = TRUE,
parallel = FALSE, nCores = min(parallel::detectCores(), 5),
derive = list(),
...) {
nsim <- safeInteger(nsim) ## remove in the future

Expand Down Expand Up @@ -4636,6 +4681,19 @@ setMethod("simulate",
data = thisData
)

# Get the MTD estimate from the samples.

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

# Create a function for additional statistical summary.

additional_stats <- lapply(derive, function(f) f(target_dose_samples))


## return the results
thisResult <-
list(
Expand All @@ -4650,7 +4708,8 @@ setMethod("simulate",
attr(
stopit,
"message"
)
),
additional_stats = additional_stats
)
return(thisResult)
}
Expand Down Expand Up @@ -4693,17 +4752,22 @@ setMethod("simulate",
stopReasons <- lapply(resultList, "[[", "stop")

stop_report <- matrix(TRUE, nrow = nsim)

additional_stats <- lapply(resultList, "[[", "additional_stats")

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


return(ret)
}
)
Expand Down
21 changes: 18 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 additional statistical summary
#' @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, 1)
),
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 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 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 @@ -319,6 +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 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 All @@ -331,6 +345,7 @@ DualSimulations <- function(rho_est,
representation(
stop_report = "matrix",
fitAtDoseMostSelected = "numeric",
additional_stats = "list",
meanFit = "list"
),
contains = "GeneralSimulationsSummary"
Expand Down
15 changes: 12 additions & 3 deletions R/Simulations-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ setMethod("summary",
ret <- .SimulationsSummary(
start,
stop_report = object@stop_report,
additional_stats = object@additional_stats,
fitAtDoseMostSelected = fitAtDoseMostSelected,
meanFit = meanFit
)
Expand All @@ -643,7 +644,6 @@ setMethod("summary",
}
)


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




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

# Report results of additional statistics summary

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

)
}


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

Expand Down
3 changes: 3 additions & 0 deletions examples/Simulations-class-DualSimulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ stop_report <- matrix(c(TRUE, FALSE), nrow = 2)

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

additional_stats <- list(1, 1)

dual_simulations_obj <- DualSimulations(
rho_est = c(0.25, 0.35),
sigma2w_est = c(0.15, 0.25),
fit_biomarker = list(c(0.3, 0.4), c(0.4, 0.5)),
fit = fit,
stop_report = stop_report,
stop_reasons = stop_reasons,
additional_stats = additional_stats,
data = data_list,
doses = doses,
seed = seed
Expand Down
11 changes: 10 additions & 1 deletion examples/Simulations-class-Simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ stop_report <- matrix(c(TRUE, FALSE), nrow = 2)

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

additional_stats <- list(1, 1)

simulations <- Simulations(fit = fit, stop_report = stop_report, stop_reasons = stop_reasons, data, doses, seed)
simulations <- Simulations(
fit = fit,
stop_report = stop_report,
stop_reasons = stop_reasons,
additional_stats = additional_stats,
data,
doses,
seed
)
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
3 changes: 3 additions & 0 deletions man/DualSimulations-class.Rd

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

Loading