| Title: | Bayesian Split-Population Survival Models with Stan |
|---|---|
| Description: | Fits Bayesian split-population (cure) survival models with Weibull or log-logistic event-time distributions using Stan via 'cmdstanr'. Provides pooled, exchangeable group-frailty, and scaled proper conditional autoregressive (CAR) spatial specifications through a common formula interface. Includes methods for coefficient extraction, prediction, frailty visualization, survival curves, and choropleth mapping of spatial effects. |
| Authors: | Sergio Béjar [aut, cre], Bumba Mukherjee [aut], Emiliano Medina-Aguilera [ctb] |
| Maintainer: | Sergio Béjar <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-28 22:15:59 UTC |
| Source: | https://github.com/cran/stanSPsurv |
Extract coefficients from a stanSPsurv fit
## S3 method for class 'stanSPsurv' coef(object, component = c("survival", "split"), ...)## S3 method for class 'stanSPsurv' coef(object, component = c("survival", "split"), ...)
object |
A fitted |
component |
Which stage: |
... |
Not used. |
A tibble of posterior summaries for the requested coefficients.
A simulated dataset of 300 post-conflict episodes across 20 countries, designed to illustrate split-population survival models. Countries are grouped into 4 geographic regions with a chain adjacency structure.
data(conflict_spells)data(conflict_spells)
A data frame with 300 rows and 8 columns:
Duration until war recurrence or censoring.
Binary indicator: 1 if war recurred, 0 if censored.
Binary: 1 if the previous war ended in decisive victory.
Log GDP per capita (standardized).
Binary: 1 if UN peacekeepers were deployed.
Factor with 20 country labels.
Factor with 4 region labels.
Integer country identifier (1–20).
The data are entirely simulated with known parameter values (beta = c(-2.0, -0.5, 0.3, -0.8), gamma = c(0.8, -0.6), shape = 1.2) and are intended for package examples and testing. They do not represent real conflict data.
Simulated for package illustration.
data(conflict_spells) head(conflict_spells)data(conflict_spells) head(conflict_spells)
Returns posterior summaries for the group-level random effects (frailties) from an exchangeable or spatial model.
frailty(object, stage = c("survival", "split"), ...)frailty(object, stage = c("survival", "split"), ...)
object |
A fitted |
stage |
Which stage: |
... |
Not used. |
A data frame with posterior summaries and group labels. Returns an empty data frame for pooled models.
Draws a choropleth (filled map) of posterior-mean frailties from a
spatial stanSPsurv model. Two back-ends are supported:
plot_choropleth( object, stage = c("survival", "split"), regions = NULL, sf_map = NULL, sf_key = NULL, palette = NULL, main = NULL, ... )plot_choropleth( object, stage = c("survival", "split"), regions = NULL, sf_map = NULL, sf_key = NULL, palette = NULL, main = NULL, ... )
object |
A fitted |
stage |
Which frailty: |
regions |
Character vector of region names for the |
sf_map |
An |
sf_key |
Column name in |
palette |
A vector of colours for the gradient. Default is a blue-white-red diverging palette. |
main |
Plot title. |
... |
Additional arguments passed to |
maps back-end (default): pass regions, a character vector of
country or region names matching the maps::world database, in the
same order as the spatial units used when fitting.
sf back-end: pass sf_map, an sf object with a geometry
column and a key column whose values match group_levels.
Invisible data frame with group, mean frailty, and assigned colour.
Caterpillar plot of posterior frailty estimates with credible intervals, ordered by posterior mean.
plot_frailty(object, stage = c("survival", "split"), prob = 0.9, ...)plot_frailty(object, stage = c("survival", "split"), prob = 0.9, ...)
object |
A fitted |
stage |
Which frailty: |
prob |
Width of the credible interval (default 0.90). |
... |
Additional arguments passed to |
Invisible data frame of frailty summaries.
Draws posterior-mean survival curves (and pointwise credible bands) for one or more covariate profiles.
plot_survival( object, newdata, times, prob = 0.9, labels = NULL, cols = NULL, main = "Survival curves", ... )plot_survival( object, newdata, times, prob = 0.9, labels = NULL, cols = NULL, main = "Survival curves", ... )
object |
A fitted |
newdata |
A data frame of covariate profiles (one row per curve). |
times |
Numeric vector of time points at which to evaluate survival. |
prob |
Width of the credible band (default 0.90). |
labels |
Optional character vector of curve labels (length
|
cols |
Optional colour vector. |
main |
Plot title. |
... |
Additional arguments passed to |
Invisible matrix of posterior-mean survival values (rows = profiles, cols = times).
Shows how the posterior-mean probability of susceptibility varies with one split-stage covariate, holding others at their means.
plot_susceptibility( object, variable, data, n_points = 100L, prob = 0.9, main = "Susceptibility", ... )plot_susceptibility( object, variable, data, n_points = 100L, prob = 0.9, main = "Susceptibility", ... )
object |
A fitted |
variable |
Name of the split-formula covariate to vary. |
data |
The original data frame used for fitting (needed to compute covariate means for held-constant variables). |
n_points |
Number of points along the covariate range (default 100). |
prob |
Width of the credible band (default 0.90). |
main |
Plot title. |
... |
Additional arguments passed to |
Invisible data frame with columns x, mean, lo, hi.
Produces a coefficient forest plot showing posterior means and 90\
credible intervals for the survival-stage (beta) and split-stage
(gamma) coefficients. Intercepts are omitted by default.
## S3 method for class 'stanSPsurv' plot( x, which = c("both", "survival", "split"), include_intercept = FALSE, prob = 0.9, main = "Coefficient plot", ... )## S3 method for class 'stanSPsurv' plot( x, which = c("both", "survival", "split"), include_intercept = FALSE, prob = 0.9, main = "Coefficient plot", ... )
x |
A fitted |
which |
Which components to plot: |
include_intercept |
Logical; include intercept terms? |
prob |
Width of the credible interval (default 0.90). |
main |
Plot title. |
... |
Additional arguments passed to |
Invisible NULL. Called for its side effect.
Compute posterior-mean susceptibility probabilities or survival probabilities for new covariate profiles.
## S3 method for class 'stanSPsurv' predict( object, newdata = NULL, type = c("susceptibility", "survival"), times = NULL, ... )## S3 method for class 'stanSPsurv' predict( object, newdata = NULL, type = c("susceptibility", "survival"), times = NULL, ... )
object |
A fitted |
newdata |
A data frame of covariate profiles. |
type |
|
times |
Numeric vector of positive time points (required when
|
... |
Not used. |
For "susceptibility", a numeric vector of posterior-mean
probabilities (one per row of newdata).
For "survival", a matrix of posterior-mean survival probabilities
(rows = profiles, columns = times).
Print a stanSPsurv fit
## S3 method for class 'stanSPsurv' print(x, ...)## S3 method for class 'stanSPsurv' print(x, ...)
x |
A fitted |
... |
Not used. |
Invisible x.
Fits a Bayesian split-population survival model with exchangeable (iid normal) group-level frailties for both the survival and split stages.
stan_exchange_spsurv( formula, split_formula, data, group, spell = NULL, form = c("weibull", "loglogistic"), ... )stan_exchange_spsurv( formula, split_formula, data, group, spell = NULL, form = c("weibull", "loglogistic"), ... )
formula |
Survival-stage formula with a two-column response
|
split_formula |
Formula for the latent susceptibility probability. |
data |
A data frame. |
group |
Group identifier, supplied as a column name or vector. |
spell |
Episode identifier. Required for counting-process responses; split-stage covariates must be constant within each episode. |
form |
Event-time distribution: |
... |
Sampling arguments passed to the CmdStan sampler
(e.g., |
An object of class stanSPsurv.
library(survival) data(lung) lung$inst <- factor(lung$inst) fit <- stan_exchange_spsurv( Surv(time, status) ~ age + sex, split_formula = ~ age, data = lung, group = inst, form = "weibull", chains = 2, iter_warmup = 200, iter_sampling = 200 ) summary(fit)library(survival) data(lung) lung$inst <- factor(lung$inst) fit <- stan_exchange_spsurv( Surv(time, status) ~ age + sex, split_formula = ~ age, data = lung, group = inst, form = "weibull", chains = 2, iter_warmup = 200, iter_sampling = 200 ) summary(fit)
Fits a Bayesian split-population (cure) survival model with no group-level heterogeneity using Stan.
stan_pooled_spsurv( formula, split_formula, data, spell = NULL, form = c("weibull", "loglogistic"), ... )stan_pooled_spsurv( formula, split_formula, data, spell = NULL, form = c("weibull", "loglogistic"), ... )
formula |
Survival-stage formula with a two-column response
|
split_formula |
Formula for the latent susceptibility probability. |
data |
A data frame. |
spell |
Episode identifier. Required for counting-process responses; split-stage covariates must be constant within each episode. |
form |
Event-time distribution: |
... |
Sampling arguments passed to the CmdStan sampler
(e.g., |
An object of class stanSPsurv.
library(survival) data(lung) fit <- stan_pooled_spsurv( Surv(time, status) ~ age + sex, split_formula = ~ age + sex, data = lung, form = "weibull", chains = 2, iter_warmup = 200, iter_sampling = 200 ) summary(fit) coef(fit, component = "survival")library(survival) data(lung) fit <- stan_pooled_spsurv( Surv(time, status) ~ age + sex, split_formula = ~ age + sex, data = lung, form = "weibull", chains = 2, iter_warmup = 200, iter_sampling = 200 ) summary(fit) coef(fit, component = "survival")
Fits a Bayesian split-population survival model with a scaled proper conditional autoregressive (BYM2) spatial structure for both the survival and split stages.
stan_spatial_spsurv( formula, split_formula, data, area, adjacency, spell = NULL, form = c("weibull", "loglogistic"), ... )stan_spatial_spsurv( formula, split_formula, data, area, adjacency, spell = NULL, form = c("weibull", "loglogistic"), ... )
formula |
Survival-stage formula with a two-column response
|
split_formula |
Formula for the latent susceptibility probability. |
data |
A data frame. |
area |
Spatial unit identifier, supplied as a column name or vector. |
adjacency |
Symmetric binary adjacency matrix ordered by the unique
values of |
spell |
Episode identifier. Required for counting-process responses; split-stage covariates must be constant within each episode. |
form |
Event-time distribution: |
... |
Sampling arguments passed to the CmdStan sampler
(e.g., |
An object of class stanSPsurv.
Returns posterior summaries (mean, median, sd, quantiles, Rhat, ESS) for all model parameters.
## S3 method for class 'stanSPsurv' summary(object, ...)## S3 method for class 'stanSPsurv' summary(object, ...)
object |
A fitted |
... |
Not used. |
A tibble of posterior summaries produced by cmdstanr::CmdStanMCMC.