compile_stan: Compile Specified Stan Models for Bayesian Survival Analysis

View source: R/survHE_funcs.R

compile_stanR Documentation

Compile Specified Stan Models for Bayesian Survival Analysis

Description

The compile_stan function pre-compiles specified Stan models used in the expertsurv package for Bayesian survival analysis. By compiling the models ahead of time, you can significantly reduce computation time during model fitting, as the models won't need to be compiled each time they're used.

Usage

compile_stan(dist_stan = c("exp", "wei", "wph", "rps", "llo", "lno"))

Arguments

dist_stan

A character vector specifying the distributions to compile. Options include:

"exp"

Exponential distribution

"wei"

Weibull distribution

"wph"

Weibull Proportional Hazards

"rps"

Restricted Piecewise Survival

"llo"

Log-Logistic distribution

"lno"

Log-Normal distribution

Defaults to c("exp", "wei", "wph", "rps", "llo", "lno").

Details

Pre-compiling Stan models is recommended when working with Bayesian methods in survival analysis, as it avoids the overhead of compiling models during each function call. This is particularly beneficial when running multiple models or iterations.

The function internally calls rstan::stan_model() for each specified distribution, compiling the Stan code associated with that model.

Value

A named list of compiled Stan models corresponding to the specified distributions.

See Also

compile_stan

Examples


library(dplyr)
# Prepare the data
# Assume 'data' is your dataset containing 'time' and 'censored' variables
data2 <- data %>%
  rename(status = censored) %>%
  mutate(
    time2 = ifelse(time > 10, 10, time),
    status2 = ifelse(time > 10, 0, status)
  )

# Pre-compile Stan models (ideally after installing the package)
# This step can be time-consuming but only needs to be done once per session
compiled_models_saved <- compile_stan()

# Fit the survival models using Bayesian methods
example1 <- fit.models.expert(
  formula = Surv(time2, status2) ~ 1,
  data = data2,
  distr = c("wei", "gom"),  # Weibull and Gompertz distributions
  method = "bayes",
  compile_mods = compiled_models_saved)

# Examine the results
summary(example1)
plot(example1)



expertsurv documentation built on April 3, 2025, 10:37 p.m.