View source: R/custom_priors.R
custom_priors | R Documentation |
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.
custom_priors(...)
## S3 method for class 'custom_priors'
print(x, ...)
... |
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 |
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 in cpp_prior_pi
. New prior
functions should use x$pi
to refer to the current value of pi
,
assuming their argument is called x
.
a
(first spatial parameter (population)): default function is
a uniform distribution implemented in cpp_prior_a
.
New prior functions should use x$a
to refer to the current value of a
,
assuming their argument is called x
.
b
(second spatial parameter (distance)): default function is
a uniform distribution implemented in cpp_prior_b
.
New prior functions should use x$b
to refer to the current value of b
,
assuming their argument is called x
.
A named list of custom functions with class custom_priors
. Values
set to NULL
will be ignored and default functions will be used
instead.
Initial version by Thibaut Jombart, rewritten by Alexis Robert (alexis.robert@lshtm.ac.uk)
## 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.