R/stan_exp_model_phe.R

Defines functions stan_exp_model_phe

Documented in stan_exp_model_phe

# Save this file as `R/stan_exp_model_phe.R`

#' Bayesian exponential model using stan
#'
#' @export
#' @param X date vector.
#' @param Y Numeric vector of number of cases
#' @param ... Arguments passed to `rstan::sampling` (iter, warmup).
#' @return An object of class `stanfit` returned by `rstan::sampling`
#'
stan_exp_model_phe <- function(X, Y, N, iter = 5000, warmup =1000, cores = 1){

  X <- as.numeric(X)
  num_data <- length(X)

  Y <- as.integer(Y)

  X_adj <- min(X)
  X <- X - X_adj


  #' Load and run stan model
  rstan::rstan_options(auto_write = TRUE)
  options(mc.cores = cores)
  fit_spline <- rstan::sampling(stanmodels$linear_phe,
                                iter=iter,
                                warmup = warmup,
                                chains=4,
                                control = list(adapt_delta=0.95,
                                               max_treedepth = 10),
                                data = list(num_data = num_data,
                                            Y = Y,
                                            X = X))


  return(fit_spline)

}
mrc-ide/reactidd documentation built on May 12, 2024, 11:47 a.m.