Skip to contents

Precompiles the Stan model code generated by create_stancode for a given model specification. This is useful when you want to avoid recompiling the model multiple times during repeated analyses or simulations.

Usage

precompile_bmcm_model(
  input_data,
  family_latent = "exponential",
  cureformula = ~1,
  model_name = NA,
  use_cmdstanr = FALSE,
  file_path = NA
)

Arguments

input_data

Data frame

family_latent

String specifying latent distribution family

cureformula

Formula for cure fraction

model_name

Optional string for model name

use_cmdstanr

Logical. If TRUE, use cmdstanr to compile the model. Default is FALSE.

file_path

Optional string for file path to save compiled model

Value

A compiled stan model object

Examples

if (FALSE) { # \dontrun{
data("surv_input_data", package = "multimcm")

# Precompile the model
compiled_model <- precompile_bmcm_model(
  input_data = surv_input_data,
  family_latent = "exponential",
  cureformula = "~ TRTA + (1 | center_id)",
  model_name = "my_precompiled_model"
)

# Pass the compiled model file path to bmcm_stan to avoid recompilation
out <- bmcm_stan(
  input_data = surv_input_data,
  formula = "Surv(time=os, event=os_event) ~ 1",
  cureformula = "~ TRTA + (1 | center_id)",
  family_latent = "exponential",
  precompiled_model_path = "./my_precompiled_model.RDS"
)
} # }