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

69: Function to compute empirical power for a list of simulated trials #70

Merged
merged 8 commits into from
Sep 26, 2023

Conversation

holgstr
Copy link
Contributor

@holgstr holgstr commented Sep 22, 2023

Fixes #69

@holgstr holgstr added the enhancement New feature or request label Sep 22, 2023
@holgstr holgstr self-assigned this Sep 22, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2023

Unit Tests Summary

    1 files    14 suites   2m 9s ⏱️
  57 tests   57 ✔️ 0 💤 0
138 runs  138 ✔️ 0 💤 0

Results for commit 7fd7f94.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2023

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  ---------
R/assertions.R                  15       0  100.00%
R/eventTracking.R               88       2  97.73%   48, 244
R/getClinicalTrials.R           64       0  100.00%
R/getSimulatedData.R           107       0  100.00%
R/getWaitTimeSum.R              29       2  93.10%   45, 48
R/hazardFunctions.R             26       0  100.00%
R/piecewiseDistribution.R       32       0  100.00%
R/piecewiseHazards.R            18       0  100.00%
R/powerEmp.R                    59       0  100.00%
R/survivalFunctions.R           96       0  100.00%
R/transitionParameters.R        42       0  100.00%
TOTAL                          576       4  99.31%

Diff against main

Filename                     Stmts    Miss  Cover
-------------------------  -------  ------  --------
R/eventTracking.R               +8       0  +0.23%
R/getClinicalTrials.R           +6       0  +100.00%
R/getSimulatedData.R            +5       0  +100.00%
R/hazardFunctions.R            +26       0  +100.00%
R/piecewiseDistribution.R       -1       0  +100.00%
R/piecewiseHazards.R            +1       0  +100.00%
R/powerEmp.R                   +59       0  +100.00%
R/survivalFunctions.R          +96       0  +100.00%
TOTAL                         +200       0  +0.37%

Results for commit: e28dc85

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Collaborator

@danielinteractive danielinteractive left a comment

Choose a reason for hiding this comment

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

nice work, thanks @holgstr - please see few suggestions below

R/powerEmp.R Outdated
#' )[[1]]
#' logRankTest(data = simTrial, typeEvent = "OS", critical = 3.4)
logRankTest <- function(data, typeEvent, critical) {
# must be `1rowTransition`, i.e. have 10 (censored) or 11 columns
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
# must be `1rowTransition`, i.e. have 10 (censored) or 11 columns
# Must be `1rowTransition`, i.e. have 10 (censored) or 11 columns.

(best to use sentence style for all comments in the code)
re: what means "1rowTransition" ? would it be better to say a bit more here instead of using this abbreviation?

R/powerEmp.R Outdated
logRankTest <- function(data, typeEvent, critical) {
# must be `1rowTransition`, i.e. have 10 (censored) or 11 columns
assert_data_frame(data, min.cols = 10, max.cols = 11)
assert_choice(typeEvent, c("OS", "PFS"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of this it is even more elegant to use typeEvent = c("OS", "PFS") in the function signature and then here typeEvent <- match.arg(typeEvent)

R/powerEmp.R Outdated
event <- data$PFSevent
}

logRank <- survdiff(Surv(time, event) ~ trt, data)
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
logRank <- survdiff(Surv(time, event) ~ trt, data)
logRank <- survival::survdiff(Surv(time, event) ~ trt, data)

since it is not in base R

R/powerEmp.R Outdated
Comment on lines 76 to 77
assert_int(eventNumPFS, lower = 1L)
assert_int(eventNumOS, lower = 1L)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could also use assert_count(..., positive = TRUE)

R/powerEmp.R Outdated
nRep <- length(simTrials)
simTrials <- lapply(simTrials, function(x) if (ncol(x) == 9) getDatasetWideFormat(x) else x)

# Censor simulated trials at time-point of OS/PFS analysis
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
# Censor simulated trials at time-point of OS/PFS analysis
# Censor simulated trials at time-point of OS/PFS analysis.

etc (sentence style)

R/powerEmp.R Outdated
simTrials <- lapply(simTrials, function(x) if (ncol(x) == 9) getDatasetWideFormat(x) else x)

# Censor simulated trials at time-point of OS/PFS analysis
trialsAnaPFS <- lapply(simTrials, censoringByNumberEvents,
Copy link
Collaborator

Choose a reason for hiding this comment

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

here we see repeated code for PFS and OS (3 calls which are basically the same for both) - here it would be useful to add an internal helper function that is then used twice here, once for PFS and once for OS to avoid the code duplication

R/powerEmp.R Outdated
# Joint power: Both PFS/OS have significant log-rank tests
powerJoint <- sum(sumPassed == 2) / nRep

c("powerPFS" = powerPFS, "powerOS" = powerOS, "powerAtLeast" = powerAtLeast, "powerJoint" = powerJoint)
Copy link
Collaborator

Choose a reason for hiding this comment

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

best to line break after each element, also consider returning a list instead of a vector - but check first the rest of the package what we use more so far in this kind of situation

@danielinteractive
Copy link
Collaborator

re: survival package - we have this currently in Suggests only (https://github.com/insightsengineering/simIDM/blob/main/DESCRIPTION#L34) I would move this to Imports and then import a single function in here: https://github.com/insightsengineering/simIDM/blob/main/R/package.R#L8 (does not matter which one, we always will prefix in our code with survival::)

R/powerEmp.R Outdated
eventNum = eventNumOS, typeEvent = "OS"
)
# Helper function to conduct log-rank tests for either PFS or OS:
passedLogRank <- function(typeEvent, eventNum, critical) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be good, but please move it out of the powerEmp function - because only then you can document and test separately

Copy link
Contributor Author

@holgstr holgstr Sep 25, 2023

Choose a reason for hiding this comment

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

thx @danielinteractive. Can I infer from this that we want "any" function defined separately (i.e., outside the main function) if it is not just a one-liner or a very simple if-else structure (or sth. similar)?

Copy link
Collaborator

@danielinteractive danielinteractive left a comment

Choose a reason for hiding this comment

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

Thanks @holgstr please see last comments below

R/powerEmp.R Show resolved Hide resolved
R/powerEmp.R Show resolved Hide resolved
R/powerEmp.R Outdated Show resolved Hide resolved
R/powerEmp.R Outdated Show resolved Hide resolved
R/powerEmp.R Show resolved Hide resolved
_pkgdown.yaml Outdated Show resolved Hide resolved
@holgstr
Copy link
Contributor Author

holgstr commented Sep 26, 2023

@danielinteractive I have implemented all of your suggestions :)

@holgstr holgstr merged commit b74388f into main Sep 26, 2023
25 checks passed
@holgstr holgstr deleted the power-idm branch September 26, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to compute empirical power for a list of simulated trials
2 participants