The package provides an implementation of piece-wise constant hazard models for time-to-event analysis of survival and competing risks data. The piecewise constant hazard models can be combined in an ensemble, the Poisson Superlearner, via cross-validated risk minimization for flexible hazard estimation. It enables estimation of survival functions and risk predictions.
The package provides:
# install.packages("devtools")
# devtools::install_github("gpitt71/poissonsuperlearner")
library(poissonsuperlearner)Fit a single PCH model and obtain absolute risk predictions.
library(poissonsuperlearner)
set.seed(42)
# Simulate synthetic survival data
d <- simulateStenoT1(
n = 50,
scenario = "alpha"
)
# Define an unpenalized Poisson hazard learner
l_glm <- Learner_glmnet(
covariates = c("sex", "diabetes_duration"),
cross_validation = FALSE,
lambda = 0,
intercept = TRUE,
penalise_nodes = FALSE
)
# Fit piecewise-constant hazard model
fit_glm <- fit_learner(
data = d,
id = "id",
status = "event",
event_time = "time",
learner = l_glm,
number_of_nodes = 5
)
# Absolute risk prediction at time horizon t = 5
predictRisk(fit_glm, newdata = d[1, ], times = 5)What happens internally?
number_of_nodes
intervals.Combine multiple hazard learners into an ensemble.
library(poissonsuperlearner)
set.seed(42)
d <- simulateStenoT1(
n = 50,
scenario = "alpha"
)
# Base learner 1: unpenalized Poisson regression
l_glm <- Learner_glmnet(
covariates = c("sex", "diabetes_duration"),
cross_validation = FALSE,
lambda = 0,
intercept = TRUE,
penalise_nodes = FALSE
)
# Base learner 2: Lasso-penalized Poisson regression
l_lasso <- Learner_glmnet(
covariates = c("value_Smoking", "value_LDL"),
cross_validation = TRUE,
alpha = 1,
intercept = TRUE,
penalise_nodes = FALSE
)
learners_list <- list(
glm = l_glm,
lasso = l_lasso
)
# Fit the superlearner
sl_fit <- Superlearner(
data = d,
id = "id",
status = "event",
event_time = "time",
learners = learners_list,
number_of_nodes = 5
)
# Absolute risk prediction from the ensemble
predictRisk(sl_fit, newdata = d[1, ], times = 5)Superlearner workflow
Learner_glmnet() – define a Poisson hazard
learner.fit_learner() – fit a single piecewise-constant hazard
model.Superlearner() – fit an ensemble of hazard
learners.predictRisk() – obtain absolute risk predictions.poissonsuperlearner is designed for:
The package focuses on modular learners, transparent cross-validation, and direct control of the piecewise hazard structure.