Package 'stanSPsurv'

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

Help Index


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 stanSPsurv object.

component

Which stage: "survival" (beta) or "split" (gamma).

...

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 stanSPsurv object.

stage

Which stage: "survival" (w) or "split" (v).

...

Not used.

Value

A data frame with posterior summaries and group labels. Returns an empty data frame for pooled models.


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 stanSPsurv object with structure = "spatial".

stage

Which frailty: "survival" (w) or "split" (v).

regions

Character vector of region names for the maps back-end, ordered to match group_levels.

sf_map

An sf object for the sf back-end.

sf_key

Column name in sf_map that matches group_levels.

palette

A vector of colours for the gradient. Default is a blue-white-red diverging palette.

main

Plot title.

...

Additional arguments passed to plot().

Details

  • 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.

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 stanSPsurv object (exchangeable or spatial).

stage

Which frailty: "survival" (w) or "split" (v).

prob

Width of the credible interval (default 0.90).

...

Additional arguments passed to plot.default().

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 stanSPsurv object.

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 nrow(newdata)).

cols

Optional colour vector.

main

Plot title.

...

Additional arguments passed to plot.default().

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 stanSPsurv object.

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 plot.default().

Value

Invisible data frame with columns x, mean, lo, hi.


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 stanSPsurv object.

which

Which components to plot: "both", "survival", or "split".

include_intercept

Logical; include intercept terms?

prob

Width of the credible interval (default 0.90).

main

Plot title.

...

Additional arguments passed to plot.default().

Value

Invisible NULL. Called for its side effect.


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 stanSPsurv object.

newdata

A data frame of covariate profiles.

type

"susceptibility" for P(susceptible) or "survival" for S(t).

times

Numeric vector of positive time points (required when type = "survival").

...

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 stanSPsurv object.

...

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 Surv(time, event).

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: "weibull" or "loglogistic".

...

Sampling arguments passed to the CmdStan sampler (e.g., chains, iter_warmup, iter_sampling, seed).

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 Surv(time, event).

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: "weibull" or "loglogistic".

...

Sampling arguments passed to the CmdStan sampler (e.g., chains, iter_warmup, iter_sampling, seed).

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 Surv(time, event).

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 area.

spell

Episode identifier. Required for counting-process responses; split-stage covariates must be constant within each episode.

form

Event-time distribution: "weibull" or "loglogistic".

...

Sampling arguments passed to the CmdStan sampler (e.g., chains, iter_warmup, iter_sampling, seed).

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 stanSPsurv object.

...

Not used.

Value

A tibble of posterior summaries produced by cmdstanr::CmdStanMCMC.