add_prior_error: Add a prior on the scale of the error component

View source: R/add_prior.R

add_prior_errorR Documentation

Add a prior on the scale of the error component

Description

Defines a prior using an Inverse Gamma distribution on the variance of the unexplained error component of the model.

Usage

add_prior_error(
  priors,
  guess,
  n,
  verbose = FALSE,
  plot = FALSE,
  show_sigma = TRUE
)

Arguments

priors

A list containing other, already defined, priors. If NULL, a list will be started with error as entry. Else, the provided list will be extended with error.

guess

Which standard deviation do you expect?

n

How much weight (n terms of observations) do you want to give your prior assumption? The larger this value, the more data observations it will take to wash out your prior distribution in case it is misspecified.

verbose

Should summarizing information be printed using message()?

plot

Should a simple plot of the implied Inverse Gamma density be drawn?

show_sigma

If TRUE (default), show the density on the scale of the standard deviation instead of the variance.

Details

Since it's usually easier to think in terms of standard deviation, guess is at the scale of the error's standard deviation. Both guess and n are translated into the shape and scale parameters of the Inverse Gamma distribution.

When thinking about this prior, frame your assumptions in terms of a sample of n observed errors with sample standard deviation guess.

Value

A list that includes a list named error, which is a list with shape and rate key-value pairs.

References

https://en.wikipedia.org/wiki/Inverse-gamma_distribution#Probability_density_function

See Also

add_prior_trend(), add_prior_level(), add_prior_seasonality(), add_prior_anomaly()

Examples

ps <- add_prior_error(priors = list(), n = 3, guess = 0.5)
print(ps)

# overwrites the existing entry
ps <- add_prior_error(priors = ps, n = 3, guess = 0.5)
print(ps)

# print summary information
add_prior_error(priors = list(), n = 3, guess = 0.5, verbose = TRUE)

# plot the implied density function with indicator for the mean
add_prior_error(priors = list(), n = 3, guess = 0.5, plot = TRUE)
add_prior_error(priors = list(), n = 2, guess = 0.5, plot = TRUE)
add_prior_error(priors = list(), n = 3, guess = 2, plot = TRUE)
add_prior_error(priors = list(), n = 1, guess = 1, plot = TRUE)

# the prior might be easier to judge on the scale of the standard deviation
add_prior_error(priors = list(), n = 1, guess = 0.5, plot = TRUE,
                show_sigma = FALSE)
add_prior_error(priors = list(), n = 1, guess = 0.5, plot = TRUE,
                show_sigma = TRUE)


timradtke/heuristika documentation built on April 24, 2023, 1:55 a.m.