MyNixOS website logo
Description

Temporal Parametric Hazard Modeling.

Provides native R implementations of the multiphase parametric hazard model of Blackstone, Naftel, and Turner (1986) <doi:10.1080/01621459.1986.10478314> with a focus on behavioral parity, transparent numerics, and reproducible validation against reference outputs from the original 'C'/'SAS' HAZARD program, originally developed at the University of Alabama at Birmingham (UAB). The 'SAS'/'C' code and this R package are currently developed and maintained at The Cleveland Clinic Foundation, and the R code was wholly developed at The Cleveland Clinic Foundation. The generalized temporal decomposition family extends to longitudinal mixed-effects settings (Rajeswaran et al. 2018 <doi:10.1177/0962280215623583>). The package is intentionally implemented in pure R first; performance-critical paths may later be accelerated with 'Rcpp' without changing the public interface.

TemporalHazard

CRAN status CRAN downloads CRAN downloads total R-CMD-check Codecov test coverage lint pkgdown site active

TemporalHazard is a pure-R implementation of the multiphase parametric hazard model of Blackstone, Naftel, and Turner (1986). It decomposes the overall hazard of an event into additive temporal phases --- early, constant, and late --- each governed by the generalized temporal decomposition family. This structure captures real clinical risk patterns that standard single-distribution models (Weibull, log-normal) cannot represent.

Provenance and maintenance

The original SAS/C HAZARD code was developed at the University of Alabama at Birmingham (UAB). The SAS/C code and this R package are currently developed and maintained at The Cleveland Clinic Foundation. The R code in TemporalHazard was wholly developed at The Cleveland Clinic Foundation.

Why multiphase?

After cardiac surgery, the risk of death is not constant. It starts high in the immediate post-operative period (early phase), settles to a low background rate (constant phase), and eventually rises again as patients age (late phase). A single Weibull curve forces a monotone shape; a multiphase model captures all three regimes simultaneously.

Additive phase decomposition showing early, constant, and late hazard components summing to the total hazard curve (CABGKUL, n=5,880)

The resulting survival curve closely tracks the nonparametric Kaplan-Meier estimate while providing a smooth, parametric representation that supports covariate adjustment, prediction, and extrapolation.

Multiphase parametric survival curve overlaid on the Kaplan-Meier estimate from the CABGKUL dataset (n=5,880)

Key capabilities

FeatureStatus
Multi-phase hazard modeling (early, constant, late phases):white_check_mark:
Five parametric distributions (Weibull, exponential, log-logistic, log-normal, multiphase):white_check_mark:
Right, left, interval, and counting-process censoring:white_check_mark:
Repeating events (epoch decomposition via Surv(start, stop, event)):white_check_mark:
Time-varying covariates (piecewise windows):white_check_mark:
Weighted events across all distributions:white_check_mark:
Automatic stepwise covariate selection (forward, backward, stepwise; Wald or AIC):white_check_mark:
Conservation of Events theorem for numerically stable parameter estimation:white_check_mark:
Covariance and correlation matrix estimation:white_check_mark:
Delta-method confidence limits on predict() (se.fit = TRUE):white_check_mark:
Seven hzr_* utility functions (Kaplan-Meier, Nelson, GOF, deciles, calibration, bootstrap, competing risks):white_check_mark:
Per-phase confidence limits (decompose = TRUE, se.fit = TRUE):construction:
4-phase example dataset and vignette:construction:

:white_check_mark: = implemented    :construction: = planned

Installation

# Install from CRAN
install.packages("TemporalHazard")
# Or install the development version from GitHub
remotes::install_github("ehrlinger/temporal_hazard")

TemporalHazard requires R >= 4.1.0 and depends on the survival package. Optional packages for visualization and vignettes include ggplot2, numDeriv, and quarto.

Quick start

Single-phase model

library(TemporalHazard)
data(cabgkul)

# Intercept-only Weibull on 5,880 CABG patients
fit <- hazard(
  survival::Surv(int_dead, dead) ~ 1,
  data  = cabgkul,
  dist  = "weibull",
  theta = c(mu = 0.10, nu = 1.0),
  fit   = TRUE
)
summary(fit)

Multiphase model

# Three-phase additive hazard decomposition
fit_mp <- hazard(
  survival::Surv(int_dead, dead) ~ 1,
  data   = cabgkul,
  dist   = "multiphase",
  phases = list(
    early    = hzr_phase("cdf", t_half = 0.2, nu = 1, m = 1,
                          fixed = "shapes"),
    constant = hzr_phase("constant"),
    late     = hzr_phase("g3",  tau = 1, gamma = 3, alpha = 1, eta = 1,
                          fixed = "shapes")
  ),
  fit = TRUE
)
summary(fit_mp)

# Per-phase decomposition of cumulative hazard
t_grid <- seq(0.01, max(cabgkul$int_dead) * 0.9, length.out = 200)
predict(fit_mp, newdata = data.frame(time = t_grid),
        type = "cumulative_hazard", decompose = TRUE)

Each phase is specified with hzr_phase(), which sets the temporal shape type and starting values. The optimizer estimates both the phase-specific scale parameters and shape parameters jointly. Covariates are supported via the formula interface (see vignette("fitting-hazard-models")).

Documentation

Development

install.packages(c("devtools", "roxygen2", "pkgdown", "testthat"))
devtools::install_deps(dependencies = TRUE)
devtools::test()
devtools::check()

GitHub Actions runs multi-platform R CMD check on every push and pull request. Coverage is published to Codecov and the pkgdown site deploys automatically from main.

See the development plan in inst/dev/DEVELOPMENT-PLAN.md for the full roadmap covering the C/SAS migration, multiphase implementation, CRAN release, and planned feature parity work. See .github/BRANCH_PROTECTION.md for recommended required-check settings that block merges when CI fails.

Metadata

Version

1.1.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows