Skip to contents

Allows users to specify a model using the brms::bf() wrapper from brms Note that brms and tidybayes must both be installed for this model wrapper to be functional.

Usage

brms_model(
  y = NULL,
  samples = NULL,
  horizon = NULL,
  model = NULL,
  n_cores = 1,
  n_chains = 4,
  n_iter = 2000,
  ...
)

Arguments

y

Numeric vector of time points to forecast

samples

Numeric, number of samples to take.

horizon

Numeric, the time horizon over which to predict.

model

A brms model wrapped in the brms::bf() function

n_cores

Numeric, the number of cores to use, default of 1

n_chains

Numeric, the number of chains to use, default of 4

n_iter

Numeric, the number of iterations in the sampler to use, default of 4000

...

additional arguments passed to brms (e.g. priors or family)

Value

A dataframe of predictions (with columns representing the time horizon and rows representing samples).

Examples

if (FALSE) {

## Used on its own
## Note: More iterations and chains should be used
library(brms)
brms_model(
  y = EpiSoon::example_obs_rts[1:10, ]$rt,
  model = brms::bf(y ~ gp(time)),
  samples = 10, horizon = 7, n_iter = 40, n_chains = 1, refresh = 0
)

## Used for forecasting
## Note that the timeout parameter has been increased to allow
## for the time for the code to be compiled
## Note: More iterations and chains should be used

forecast_rt(EpiSoon::example_obs_rts[1:10, ],
  model = function(...) {
    brms_model(model = brms::bf(y ~ gp(time)), n_iter = 40, n_chains = 1, ...)
  },
  horizon = 7, samples = 10, timeout = 300
)
}