Skip to contents

Helper function to extract both user-specifiable and hard-coded prior data and assemble it in the appropriate form for the prior.info element of a salmonIPMfit object.

Usage

get_prior_info(stan_data, stanmodel, pars)

Arguments

stan_data

Named list of input data passed to rstan::sampling() for fitting an IPM, as returned by stan_data().

stanmodel

An object of S4 class stanmodel as constructed by stan_model() or by rstantools during installation of salmonIPM-package and stored internally in salmonIPM:::stanmodels.

pars

Character vector of hyperparameters for which priors are specified.

Value

A named list of priors on pars. Each element is itself a named list representing the prior in the format returned by the functions in priors with an additional attribute "type".

Details

Priors include (1) Those that are user-specifiable through the salmonIPM(priors) argument (whether modified or defaults) and returned in Stan format by stan_data(), (2) those that are explicitly hard-coded in the model block of stanmodel, and (3) those that are implicitly defined by bounds on parameter declarations.

To extract type (1), get_prior_info() calls the priors functions using the contents of stan_data.

To extract type (2), get_prior_info() parses stanmodel into lines of text and then uses regex to pull out the sampling statement for each parameter as a string, which corresponds directly to a priors function call.

Type (3) is extracted similarly to type (2), but bound declarations are also used to set the bounds attribute on otherwise unbounded priors (e.g. normal) of types (1) and (2).