Exp1 {nieve}R Documentation

Density, Distribution Function, Quantile Function and Random Generation for the One-Parameter Exponential Distribution

Description

Density, distribution function, quantile function and random generation for the one-parameter Exponential Distribution distribution with scale parameter scale.

Usage

dexp1(x, scale = 1, log = FALSE, deriv = FALSE, hessian = FALSE)

pexp1(q, scale = 1, lower.tail = TRUE, deriv = FALSE, hessian = FALSE)

qexp1(p, scale = 1, lower.tail = TRUE, deriv = FALSE, hessian = FALSE)

rexp1(n, scale = 1, array)

Arguments

x, q

Vector of quantiles.

scale

Scale parameter. Numeric vector with suitable length, see Details.

log

Logical; if TRUE, densities p are returned as log(p).

deriv

Logical. If TRUE, the gradient of each computed value w.r.t. the parameter vector is computed, and returned as a "gradient" attribute of the result. This is a numeric array with dimension c(n, 1) where n is the length of the first argument, i.e. x, p or q, depending on the function.

hessian

Logical. If TRUE, the Hessian of each computed value w.r.t. the parameter vector is computed, and returned as a "hessian" attribute of the result. This is a numeric array with dimension c(n, 1, 1) where n is the length of the first argument, i.e. x, p or depending on the function.

lower.tail

Logical; if TRUE (default), probabilities are \textrm{Pr}[X \leq x], otherwise, \textrm{Pr}[X > x].

p

Vector of probabilities.

n

Sample size.

array

Logical. If TRUE, the simulated values form a numeric matrix with n columns and np rows where np is the number of exponential parameter values i.e., the length of scale. This option is useful to cope with so-called non-stationary models with exponential margins. See Examples. The default value is length(scale) > 1.

Details

The survival and density functions are given by

S(x) = \exp\{-x / \sigma\} \qquad f(x) = \frac{1}{\sigma} \exp\{-x / \sigma\} \qquad (x > 0)

where \sigma is the scale parameter. This distribution is the Generalized Pareto Distribution for a shape \xi = 0.

The probability functions d, p and q all allow the parameter scale to be a vector. Then the recycling rule is used to get two vectors of the same length, corresponding to the first argument and to the scale parameter. This behaviour is the standard one for the probability functions of the stats package but is unusual in R packages devoted to Extreme Value in which the parameters must generally have length one. Note that the provided functions can be used e.g. to evaluate the quantile with a given probability for a large number of values of the parameter vector shape. This is frequently required in he Bayesian framework with MCMC inference.

Value

A numeric vector with its length equal to the maximum of the two lengths: that of the first argument and that of the parameter scale. When deriv is TRUE, the returned value has an attribute named "gradient" which is a matrix with n lines and 1 column containing the derivative. A row contains the partial derivative of the corresponding element w.r.t. the parameter "scale".

Note

The attributes "gradient" and "hessian" have dimension c(n, 1) and c(n, 1, 1), even when n equals 1. Use the drop method on these objects to drop the extra dimension if wanted i.e. to get a gradient vector and a Hessian matrix.

See Also

The exponential distribution Exponential with rate being the inverse scale.

Examples

## Illustrate the effect of recycling rule.
pexp1(1.0, scale = 1:4, lower.tail = FALSE) - exp(-1.0 / (1:4))
pexp1(1:4, scale = 1:4, lower.tail = FALSE) - exp(-1.0)

## With gradient and Hessian.
pexp1(c(1.1, 1.7), scale = 1, deriv = TRUE, hessian = TRUE)

ti <- 1:60; names(ti) <- 2000 + ti
sigma <- 1.0 + 0.7 * ti
## simulate 40 paths
y <- rexp1(n = 40, scale = sigma)
matplot(ti, y, type = "l", col = "gray", main = "varying scale")
lines(ti, apply(y, 1, mean))


[Package nieve version 0.1.3 Index]