| Type: | Package |
| Title: | Bayesian Split-Population Survival Models with Stan |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0) |
| Imports: | stats |
| Suggests: | cmdstanr, countrycode, knitr, maps, rmarkdown, sf, testthat (≥ 3.0.0), survival |
| VignetteBuilder: | knitr |
| Additional_repositories: | https://stan-dev.r-universe.dev |
| SystemRequirements: | CmdStan (https://mc-stan.org/users/interfaces/cmdstan) |
| Config/testthat/edition: | 3 |
| URL: | https://github.com/Sergio-Bejar/stanSPsurv |
| BugReports: | https://github.com/Sergio-Bejar/stanSPsurv/issues |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-06 04:31:01 UTC; sergiobejar |
| Author: | Sergio Béjar [aut, cre], Bumba Mukherjee [aut], Emiliano Medina-Aguilera [ctb] |
| Maintainer: | Sergio Béjar <sergio.bejar@cide.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-28 15:00:08 UTC |
stanSPsurv: 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.
Author(s)
Maintainer: Sergio Béjar sergio.bejar@cide.edu
Authors:
Sergio Béjar sergio.bejar@cide.edu
Bumba Mukherjee
Other contributors:
Emiliano Medina-Aguilera [contributor]
See Also
Useful links:
Report bugs at https://github.com/Sergio-Bejar/stanSPsurv/issues
Extract coefficients from a stanSPsurv fit
Description
Extract coefficients from a stanSPsurv fit
Usage
## S3 method for class 'stanSPsurv'
coef(object, component = c("survival", "split"), ...)
Arguments
object |
A fitted |
component |
Which stage: |
... |
Not used. |
Value
A tibble of posterior summaries for the requested coefficients.
Simulated post-conflict survival data
Description
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.
Usage
data(conflict_spells)
Format
A data frame with 300 rows and 8 columns:
- time
Duration until war recurrence or censoring.
- event
Binary indicator: 1 if war recurred, 0 if censored.
- victory
Binary: 1 if the previous war ended in decisive victory.
- gdp
Log GDP per capita (standardized).
- peacekeeping
Binary: 1 if UN peacekeepers were deployed.
- country
Factor with 20 country labels.
- region
Factor with 4 region labels.
- country_id
Integer country identifier (1–20).
Details
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.
Source
Simulated for package illustration.
Examples
data(conflict_spells)
head(conflict_spells)
Extract group or spatial frailties
Description
Returns posterior summaries for the group-level random effects (frailties) from an exchangeable or spatial model.
Usage
frailty(object, stage = c("survival", "split"), ...)
Arguments
object |
A fitted |
stage |
Which stage: |
... |
Not used. |
Value
A data frame with posterior summaries and group labels. Returns an empty data frame for pooled models.
Plot a stanSPsurv fit
Description
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.
Usage
## S3 method for class 'stanSPsurv'
plot(
x,
which = c("both", "survival", "split"),
include_intercept = FALSE,
prob = 0.9,
main = "Coefficient plot",
...
)
Arguments
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 |
Value
Invisible NULL. Called for its side effect.
Choropleth map of spatial frailties
Description
Draws a choropleth (filled map) of posterior-mean frailties from a
spatial stanSPsurv model. Two back-ends are supported:
Usage
plot_choropleth(
object,
stage = c("survival", "split"),
regions = NULL,
sf_map = NULL,
sf_key = NULL,
palette = NULL,
main = NULL,
...
)
Arguments
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 |
Details
-
mapsback-end (default): passregions, a character vector of country or region names matching themaps::worlddatabase, in the same order as the spatial units used when fitting. -
sfback-end: passsf_map, ansfobject with a geometry column and a key column whose values matchgroup_levels.
Value
Invisible data frame with group, mean frailty, and assigned colour.
Plot group or spatial frailties
Description
Caterpillar plot of posterior frailty estimates with credible intervals, ordered by posterior mean.
Usage
plot_frailty(object, stage = c("survival", "split"), prob = 0.9, ...)
Arguments
object |
A fitted |
stage |
Which frailty: |
prob |
Width of the credible interval (default 0.90). |
... |
Additional arguments passed to |
Value
Invisible data frame of frailty summaries.
Plot survival curves from a stanSPsurv fit
Description
Draws posterior-mean survival curves (and pointwise credible bands) for one or more covariate profiles.
Usage
plot_survival(
object,
newdata,
times,
prob = 0.9,
labels = NULL,
cols = NULL,
main = "Survival curves",
...
)
Arguments
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 |
Value
Invisible matrix of posterior-mean survival values (rows = profiles, cols = times).
Plot susceptibility across a covariate range
Description
Shows how the posterior-mean probability of susceptibility varies with one split-stage covariate, holding others at their means.
Usage
plot_susceptibility(
object,
variable,
data,
n_points = 100L,
prob = 0.9,
main = "Susceptibility",
...
)
Arguments
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 |
Value
Invisible data frame with columns x, mean, lo, hi.
Predict from a stanSPsurv fit
Description
Compute posterior-mean susceptibility probabilities or survival probabilities for new covariate profiles.
Usage
## S3 method for class 'stanSPsurv'
predict(
object,
newdata = NULL,
type = c("susceptibility", "survival"),
times = NULL,
...
)
Arguments
object |
A fitted |
newdata |
A data frame of covariate profiles. |
type |
|
times |
Numeric vector of positive time points (required when
|
... |
Not used. |
Value
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
Description
Print a stanSPsurv fit
Usage
## S3 method for class 'stanSPsurv'
print(x, ...)
Arguments
x |
A fitted |
... |
Not used. |
Value
Invisible x.
Fit an exchangeable-frailty split-population survival model
Description
Fits a Bayesian split-population survival model with exchangeable (iid normal) group-level frailties for both the survival and split stages.
Usage
stan_exchange_spsurv(
formula,
split_formula,
data,
group,
spell = NULL,
form = c("weibull", "loglogistic"),
...
)
Arguments
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., |
Value
An object of class stanSPsurv.
Examples
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)
Fit a pooled split-population survival model
Description
Fits a Bayesian split-population (cure) survival model with no group-level heterogeneity using Stan.
Usage
stan_pooled_spsurv(
formula,
split_formula,
data,
spell = NULL,
form = c("weibull", "loglogistic"),
...
)
Arguments
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., |
Value
An object of class stanSPsurv.
Examples
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")
Fit a spatial CAR split-population survival model
Description
Fits a Bayesian split-population survival model with a scaled proper conditional autoregressive (BYM2) spatial structure for both the survival and split stages.
Usage
stan_spatial_spsurv(
formula,
split_formula,
data,
area,
adjacency,
spell = NULL,
form = c("weibull", "loglogistic"),
...
)
Arguments
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., |
Value
An object of class stanSPsurv.
Summarise a stanSPsurv fit
Description
Returns posterior summaries (mean, median, sd, quantiles, Rhat, ESS) for all model parameters.
Usage
## S3 method for class 'stanSPsurv'
summary(object, ...)
Arguments
object |
A fitted |
... |
Not used. |
Value
A tibble of posterior summaries produced by cmdstanr::CmdStanMCMC.