Skip to contents

How brms models can be initialized depends on the backend. The method that all backends supports is as a list (one for each chain) of lists (one for each variable) with numeric values. Since this requires knowing how many chains are being run, which may not be available when the model is being defined, and to support random initialization, the rstan backend also supports initialization as a function returning a list of functions (one for each parameter) returning a numeric array of length 1. Also, to support the common use-case of initializing everything to zero or randomly in the range (-2, 2) on the unconstrained scale, rstan also supports initializing with 0 and "random".

To make BayesPharma more backend agnostic, this helper function takes the an init and the number of chains and reduces it to the list of list format.

Usage

eval_init(init, sdata = NULL, algorithm = "sampling", chains = 4)

Arguments

init

One of

  • NULL, numeric, character in which case use the default rstan init.

  • named list with one element for each parameter. The values can be either array, numeric, or a function returning a numeric value

sdata

result of running brms::make_standata(), in particular it it should be list having elements K_<parameter_name> for each parameter in the model. Where the value of these elements is the dimension of the parameter.

algorithm

character string naming the estimation approach to use. see brms::brm for details. This is needed here because some algorithms can be run in parallel from different initialization points, which affects the dimension of the initial values if the chains parameter is NULL.

chains

numeric number of chains for which to initialize

Value

list of list form of model initialization