bssm_prior: Prior objects for bssm models

uniform_priorR Documentation

Prior objects for bssm models

Description

These simple objects of class bssm_prior are used to construct a prior distributions for the hyperparameters theta for some of the model objects of bssm package. Note that these priors do not include the constant terms as they do not affect the sampling.

Usage

uniform_prior(init, min, max)

uniform(init, min, max)

halfnormal_prior(init, sd)

halfnormal(init, sd)

normal_prior(init, mean, sd)

normal(init, mean, sd)

tnormal_prior(init, mean, sd, min = -Inf, max = Inf)

tnormal(init, mean, sd, min = -Inf, max = Inf)

gamma_prior(init, shape, rate)

gamma(init, shape, rate)

Arguments

init

Initial value for the parameter, used in initializing the model components and as a starting values in MCMC.

min

Lower bound of the uniform and truncated normal prior.

max

Upper bound of the uniform and truncated normal prior.

sd

Positive value defining the standard deviation of the (underlying i.e. non-truncated) Normal distribution.

mean

Mean of the Normal prior.

shape

Positive shape parameter of the Gamma prior.

rate

Positive rate parameter of the Gamma prior.

Details

Currently supported priors are

  • uniform prior (uniform()) with a probability density function (pdf) defined as \frac{1}{max - min} for min < theta < max.

  • normal (normal()), a normal distribution parameterized via mean and standard deviation, i.e. N(mean, sd^2).

  • truncated normal distribution (tnormal()), a normal distribution with known truncation points (from below and/or above). Ignoring the scaling factors, this corresponds to the pdf of N(mean, sd^2) when min < theta < max and zero otherwise.

  • half-normal (halfnormal()) with a pdf matching the pdf of the truncated normal distribution with min=0 and max=inf.

  • gamma (gamma), a gamma distribution with shape and rate parameterization.

All parameters are vectorized so for regression coefficient vector beta you can define prior for example as normal(0, 0, c(10, 20)).

For the general exponential models, i.e. models built with the ssm_ulg, ssm_ung, ssm_mlg, and ssm_mng, you can define arbitrary priors by defining the prior_fn function, which takes the one argument, theta, corresponding to the hyperparameter vector of the model, and returns a log-density of the (joint) prior (see the R Journal paper and e.g. ssm_ulg for examples). Similarly, the priors for the non-linear models (ssm_nlg) and SDE models (ssm_sde) are constructed via C++ snippets (see the vignettes for details).

The longer name versions of the prior functions with _prior ending are identical with shorter versions and they are available only to avoid clash with R's primitive function gamma (other long prior names are just for consistent naming).

Value

object of class bssm_prior or bssm_prior_list in case of multiple priors (i.e. multiple regression coefficients).

Examples


# create uniform prior on [-1, 1] for one parameter with initial value 0.2:
uniform(init = 0.2, min = -1.0, max = 1.0)
# two normal priors at once i.e. for coefficients beta:
normal(init = c(0.1, 2.5), mean = 0.1, sd = c(1.5, 2.8))
# Gamma prior (not run because autotest tests complain)
# gamma(init = 0.1, shape = 2.5, rate = 1.1)
# Same as
gamma_prior(init = 0.1, shape = 2.5, rate = 1.1)
# Half-normal
halfnormal(init = 0.01, sd = 0.1)
# Truncated normal
tnormal(init = 5.2, mean = 5.0, sd = 3.0, min = 0.5, max = 9.5)


# Further examples for diagnostic purposes:
uniform(c(0, 0.2), c(-1.0, 0.001), c(1.0, 1.2))
normal(c(0, 0.2), c(-1.0, 0.001), c(1.0, 1.2))
tnormal(c(2, 2.2), c(-1.0, 0.001), c(1.0, 1.2), c(1.2, 2), 3.3)
halfnormal(c(0, 0.2), c(1.0, 1.2))
# not run because autotest bug
# gamma(c(0.1, 0.2), c(1.2, 2), c(3.3, 3.3))

# longer versions:
uniform_prior(init = c(0, 0.2), min = c(-1.0, 0.001), max = c(1.0, 1.2))
normal_prior(init = c(0, 0.2), mean = c(-1.0, 0.001), sd = c(1.0, 1.2))
tnormal_prior(init = c(2, 2.2), mean = c(-1.0, 0.001), sd = c(1.0, 1.2),
  min = c(1.2, 2), max = 3.3)
halfnormal_prior(init = c(0, 0.2), sd = c(1.0, 1.2))
gamma_prior(init = c(0.1, 0.2), shape = c(1.2, 2), rate = c(3.3, 3.3))


bssm documentation built on Nov. 2, 2023, 6:25 p.m.