Skip to content

Commit

Permalink
Merge branch 'main' into 74_pwcsurvos_smooth
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinteractive authored Dec 7, 2023
2 parents 8cc1709 + bbe7658 commit 45e1544
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 31 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export(ExpQuantOS)
export(ExpSurvOS)
export(ExpSurvPFS)
export(PCWInversionMethod)
export(PFSOSInteg)
export(PWCsurvOS)
export(PWCsurvPFS)
export(WeibOSInteg)
Expand Down Expand Up @@ -62,7 +61,6 @@ export(integrateVector)
export(logRankTest)
export(log_p11)
export(negLogLik)
export(p11Integ)
export(passedLogRank)
export(piecewise_exponential)
export(prepareData)
Expand Down
37 changes: 24 additions & 13 deletions R/corPFSOS.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# survPFS ----

#' PFS Survival Function for Different Transition Models
#'
#' @param transition (`TransitionParameters`)\cr
Expand Down Expand Up @@ -53,6 +55,8 @@ survPFS.PWCTransition <- function(transition, t) {
)
}

# survOS ----

#' OS Survival Function for Different Transition Models
#'
#' @param transition (`TransitionParameters`)\cr
Expand Down Expand Up @@ -113,6 +117,8 @@ survOS.PWCTransition <- function(transition, t) {
)
}

# expval ----

#' Helper Function for Computing E(PFS^2)
#'
#' @param x (`numeric`)\cr variable of integration.
Expand Down Expand Up @@ -145,28 +151,26 @@ expvalOSInteg <- function(x, transition) {
x * survOS(transition = transition, t = x)
}

# p11 ----

#' Helper Function for `log_p11()`
#'
#' @param x (`numeric`)\cr variable of integration.
#' @param transition (`TransitionParameters`)\cr
#' see [exponential_transition()], [weibull_transition()] or [piecewise_exponential()] for details.
#'
#' @return Hazard rate at the specified time for the transition from progression to death.
#' @export
#'
#' @examples
#' transition <- exponential_transition(h01 = 1.2, h02 = 1.5, h12 = 1.6)
#' p11Integ(2, transition)
#' @keywords internal
p11Integ <- function(x, transition) {
haz(transition = transition, t = x, trans = 3)
}

#' Probability of Remaining in Progression Between Two Time Points for Different Transition Models.
#' Probability of Remaining in Progression Between Two Time Points for Different Transition Models
#'
#' @param transition (`TransitionParameters`)\cr
#' see [exponential_transition()], [weibull_transition()] or [piecewise_exponential()] for details.
#' @param s (`numeric`)\cr lower time point.
#' @param t (`numeric`)\cr higher time point.
#' @param s (`numeric`)\cr lower time points.
#' @param t (`numeric`)\cr higher time points.
#' @return This returns the natural logarithm of the probability of remaining in progression (state 1)
#' between two time points, conditional on being in state 1 at the lower time point.
#'
Expand All @@ -176,6 +180,11 @@ p11Integ <- function(x, transition) {
#' transition <- exponential_transition(h01 = 1.2, h02 = 1.5, h12 = 1.6)
#' log_p11(transition, 1, 3)
log_p11 <- function(transition, s, t) {
assert_numeric(s, finite = TRUE, any.missing = FALSE, lower = 0)
assert_numeric(t, finite = TRUE, any.missing = FALSE, lower = 0)
assert_true(identical(length(s), length(t)))
assert_true(all(t > s))

intval <- mapply(function(s, t) {
stats::integrate(p11Integ,
lower = s,
Expand All @@ -186,19 +195,19 @@ log_p11 <- function(transition, s, t) {
-intval
}

# PFSOS ----

#' Helper Function for `survPFSOS()`
#'
#' @param u (`numeric`)\cr variable of integration.
#' @param t (`numeric`)\cr time at which the value of the PFS*OS survival function is to be computed.
#' @param transition (`TransitionParameters`)\cr
#' see [exponential_transition()], [weibull_transition()] or [piecewise_exponential()] for details.
#'
#' @return Numeric result of the integrand used to calculate the PFS*OS survival function.
#' @export
#' @note Not all vectors `u` and `t` work here due to assertions in [log_p11()].
#'
#' @examples
#' transition <- exponential_transition(h01 = 1.2, h02 = 1.5, h12 = 1.6)
#' PFSOSInteg(1, 2, transition)
#' @return Numeric result of the integrand used to calculate the PFS*OS survival function.
#' @keywords internal
PFSOSInteg <- function(u, t, transition) {
exp(log_p11(transition, u, t / u) + log(survPFS(transition, u)) + log(haz(transition, u, 1)))
}
Expand All @@ -222,6 +231,8 @@ survPFSOS <- function(t, transition) {
})
}

# correlation ----

#' Correlation of PFS and OS event times for Different Transition Models
#'
#' @param transition (`TransitionParameters`)\cr
Expand Down
11 changes: 10 additions & 1 deletion R/estimateParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#' - id (`integer`): patient id.
#' - from (`integer`): start event state.
#' - to (`integer`): end event state.
#' - trans (`integer`): transition (1, 2 or 3) identifier.
#' - trans (`integer`): transition (1, 2 or 3) identifier
#' - `1`: Transition from state 0 (stable) to 1 (progression).
#' - `2`: Transition from state 0 (stable) to 2 (death).
#' - `3`: Transition from state 1 (progression) to 2 (death).
#' - entry (`numeric`): time at which the patient begins to be at risk for the transition.
#' - exit (`numeric`): time at which the patient ends to be at risk for the transition.
#' - status (`logical`): event indicator for the transition.
Expand Down Expand Up @@ -92,6 +95,12 @@ negLogLik <- function(transition, data) {
#' @param t (`numeric`)\cr time at which hazard is to be computed.
#' @param trans (`integer`)\cr index specifying the transition type.
#'
#' @details
#' The transition types are:
#' - `1`: Transition from state 0 (stable) to 1 (progression).
#' - `2`: Transition from state 0 (stable) to 2 (death).
#' - `3`: Transition from state 1 (progression) to 2 (death).
#'
#' @return The hazard rate for the specified transition and time.
#' @export
#'
Expand Down
2 changes: 0 additions & 2 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ reference:
- expvalPFSInteg
- expvalOSInteg
- log_p11
- p11Integ
- PFSOSInteg
- survPFS
- survPFSOS
- survOS
6 changes: 3 additions & 3 deletions man/PFSOSInteg.Rd

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

8 changes: 8 additions & 0 deletions man/haz.Rd

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

8 changes: 4 additions & 4 deletions man/log_p11.Rd

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

5 changes: 1 addition & 4 deletions man/p11Integ.Rd

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

7 changes: 6 additions & 1 deletion man/prepareData.Rd

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

Loading

0 comments on commit 45e1544

Please sign in to comment.