Skip to contents

hazrd is an R package for evaluating and visualizing Polygenic Hazard Score (PHS) analyses. It provides a consistent, tidy-first API for computing survival-based discrimination metrics, bootstrapped confidence intervals, and Kaplan-Meier curves.

Installation

Latest release

Install the current stable release directly from GitHub:

# install.packages("devtools")
devtools::install_github("amorris28/hazrd")

Installing from the default (main) branch is equivalent to installing the latest tagged release.

Development version

To get the current development version (may contain unreleased features):

devtools::install_github("amorris28/hazrd@dev")

Getting started

For a full introduction see the vignette on the hazrd pkgdown website.

Quick example

library(hazrd)

# Compute HR, C-index, OR, and HR_SD in one call
phs_metrics(
  test_data,
  metrics = c("HR", "C_index", "OR", "HR_SD"),
  or_age  = 70)

# Bootstrapped confidence intervals
phs_metrics(
  test_data,
  metrics   = c("HR", "C_index"),
  bootstrap = TRUE,
  n_boot    = 999,
  seed      = 42
)

# Kaplan-Meier plot with overlapping intervals (returns a ggplot object)
phs_km_curve(test_data)

# Overlapping intervals — top 5%, top 20%, bottom 20%
phs_km_curve(test_data, intervals = list(c(0.95, 1), c(0.80, 1), c(0, 0.20)))

# Legacy exclusive bands via breaks
km_data <- phs_km_curve(test_data, intervals = NULL, breaks = c(0.20, 0.40, 0.60, 0.80), output = "data")

Planned features

The following are on the roadmap for future releases. Contributions welcome.

  • phs_abs_risk() — absolute (cumulative incidence) risk curves with competing risk support (km, aalen_johansen, fine_gray methods)
  • phs_percentile() — compute percentile ranks; optionally relative to a reference population via ref_data
  • phs_cut() — assign individuals to percentile strata with human-readable factor labels
  • phs_describe() — descriptive statistics (n, events, median follow-up, PHS mean/SD) by stratum
  • phs_calibration() — calibration plot and Hosmer-Lemeshow statistic
  • theme_phs() / scale_color_phs() — default ggplot2 theme and colour scale for hazrd plots
  • Uno’s C-index — IPCW-weighted concordance for heavily censored data (cindex_method = "uno" in phs_metrics())
  • Parallel bootstrapparallel = "multicore" / "snow" via boot::boot() (argument exists; only "no" is currently active)
  • Risk table — numbers-at-risk appended below KM curves (risk_table = TRUE in phs_km())
  • Alternative HR methodscontinuous_point and categorical (hr_method argument in phs_metrics(); stubs exist)