custom_priors {o2geosocial} | R Documentation |
Customise priors for outbreaker
Description
Priors can be specified in several ways in o2geosocial (see details and examples). The most flexible way to specify a prior is to provide a prior function directly. This function must take an argument 'param', which is a list which contains all the states of the parameters and augmented data. See the documentation of create_param for more information.
Usage
custom_priors(...)
## S3 method for class 'custom_priors'
print(x, ...)
Arguments
... |
A list or a series of named, comma-separated functions implementing priors. Each function must have a single argument, which corresponds to a 'outbreaker_param' list. |
x |
an |
Details
There are three ways a user can specify priors:
1) Default: this is what happens when the 'config' has default values of
prior parameters.
2) Customized parameters: in this case, the prior functions are the default
ones from the package, but will use custom parameters, specified by the user
through create_config
.
3) Customized functions: in this case, prior functions themselves are
specified by the user, through the '...' argument of 'custom_priors'. The
requirements is that such functions must have either hard-coded parameters or
enclosed values. They will take a single argument which is a list containing
all model parameters with the class 'outbreaker_param'. ALL PRIORS functions
are expected to return values on a LOG SCALE.
Priors currently used for the model are:
-
pi
(reporting probability): default function is a beta distribution implemented incpp_prior_pi
. New prior functions should usex$pi
to refer to the current value ofpi
, assuming their argument is calledx
. -
a
(first spatial parameter (population)): default function is a uniform distribution implemented incpp_prior_a
. New prior functions should usex$a
to refer to the current value ofa
, assuming their argument is calledx
. -
b
(second spatial parameter (distance)): default function is a uniform distribution implemented incpp_prior_b
. New prior functions should usex$b
to refer to the current value ofb
, assuming their argument is calledx
.
Value
A named list of custom functions with class custom_priors
. Values
set to NULL
will be ignored and default functions will be used
instead.
Author(s)
Initial version by Thibaut Jombart, rewritten by Alexis Robert (alexis.robert@lshtm.ac.uk)
Examples
## SPECIFYING PRIOR PARAMETERS
## Default values: pi follows a beta distribution (parameters 10, 1),
## a and b follow a uniform distribution (parameters 0, 5)
default_config <- create_config()
## Use the variables prior_a, prior_b and prior_pi to change the parameters
## of the prior distributions can be
new_config <- create_config(prior_a = c(0,5), prior_b = c(0,5),
prior_pi = c(2, 1))
## SPECIFYING A NEW PRIOR FUNCTION
## Example: flat prior for pi between 0.5 and 1
f <- function(x) {ifelse(x$pi > 0.5, log(2), log(0))}
priors <- custom_priors(pi = f)
## test the new prior distribution
priors$pi(list(pi=1))
priors$pi(list(pi=.6))
priors$pi(list(pi=.2))
priors$pi(list(pi=.49))