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.
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.
To get the current development version (may contain unreleased features):
devtools::install_github("amorris28/hazrd@dev")For a full introduction see the vignette on the hazrd pkgdown website.
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")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_graymethods)phs_percentile()— compute percentile ranks; optionally relative to a reference population viaref_dataphs_cut()— assign individuals to percentile strata with human-readable factor labelsphs_describe()— descriptive statistics (n, events, median follow-up, PHS mean/SD) by stratumphs_calibration()— calibration plot and Hosmer-Lemeshow statistictheme_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"inphs_metrics()) - Parallel bootstrap —
parallel = "multicore"/"snow"viaboot::boot()(argument exists; only"no"is currently active) - Risk table — numbers-at-risk appended below KM curves
(
risk_table = TRUEinphs_km()) - Alternative HR methods —
continuous_pointandcategorical(hr_methodargument inphs_metrics(); stubs exist)