interval: Constrain to Interval

Description Usage Arguments Details Value Author(s) See Also Examples

Description

This function constrains the value(s) of a scalar, vector, matrix, or array to a specified interval, [a,b]. In Bayesian inference, it is often used both to truncate a parameter to an interval, such as p(theta) in [a,b]. The interval function is often used in conjunction with the dtrunc function to truncate the prior probability distribution associated with the constrained parameter. While dtrunc prevents assigning density outside of its interval and re-estimates density within the interval, the interval function is used to prevent the parameter from moving outside of the interval in the first place.

After the parameter is constrained to an interval in IterativeQuadrature, LaplaceApproximation, LaplacesDemon, PMC, or VariationalBayes, the constrained parameter should be updated back into the parm vector, so the algorithm knows it has been constrained.

This is unrelated to the probability interval (see p.interval and LPL.interval).

Usage

1
interval(x, a=-Inf, b=Inf, reflect=TRUE)

Arguments

x

This required argument is a scalar, vector, matrix or array, and its elements will be constrained to the interval [a,b].

a

This optional argument allows the specification of the lower bound of the interval, and defaults to -Inf.

b

This optional argument allows the specification of the upper bound of the interval, and defaults to Inf.

reflect

Logical. When TRUE, a value outside of the constrained interval is reflected or bounced back into the interval. When FALSE, a value outside of the interval is assigned the nearest boundary of the interval. This argument defaults to TRUE.

Details

It is common for a parameter to be constrained to an interval. For example, a scale parameter is positive-only. Nonetheless, the user should consider re-parameterizing by transforming the constrained parameter to the real line. To continue the example, a scale parameter may be log-transformed. A parameter that is re-parameterized to the real line often mixes better in MCMC, exhibiting a higher effective sample size (ESS), and each evaluation of the model specification function is faster as well. Nonetheless, there are many cases where it is better for the parameter to be constrained to an interval.

Value

The interval function returns a scalar, vector, matrix, or array in accord with its argument, x. Each element is constrained to the interval [a,b].

Author(s)

Statisticat, LLC. software@bayesian-inference.com

See Also

dtrunc, ESS, IterativeQuadrature, LaplaceApproximation, LaplacesDemon, LPL.interval, PMC, p.interval, VariationalBayes.

Examples

1
2
3
4
5
6
#See the Examples vignette for numerous examples.
library(LaplacesDemon)
x <- 2
interval(x,0,1)
X <- matrix(runif(25,-2,2),5,5)
interval(X,-1,1)

benmarwick/LaplacesDemon documentation built on May 12, 2019, 12:59 p.m.