momIntegrated: Moments Using Integration

View source: R/momIntegrated.R

momIntegratedR Documentation

Moments Using Integration

Description

Calculates moments and absolute moments about a given location for the generalized hyperbolic and related distributions.

Usage

momIntegrated(densFn, order, param = NULL, about = 0, absolute = FALSE)

Arguments

densFn

Character. The name of the density function whose moments are to be calculated. See Details.

order

Numeric. The order of the moment or absolute moment to be calculated.

param

Numeric. A vector giving the parameter values for the distribution specified by densFn. If no param values are specified, then the default parameter values of each distribution are used instead.

about

Numeric. The point about which the moment is to be calculated.

absolute

Logical. Whether absolute moments or ordinary moments are to be calculated. Default is FALSE.

Details

Denote the density function by f. Then if order=k and about=a, momIntegrated calculates

\int_{-\infty}^\infty (x - a)^k f(x) dx

when absolute = FALSE and

\int_{-\infty}^\infty |x - a|^k f(x) dx

when absolute = TRUE.

Only certain density functions are permitted.

When densFn="ghyp" or "generalized hyperbolic" the density used is dghyp. The default value for param is c(1,1,0,1,0).

When densFn="hyperb" or "hyperbolic" the density used is dhyperb. The default value for param is c(0,1,1,0).

When densFn="gig" or "generalized inverse gaussian" the density used is dgig. The default value for param is c(1,1,1).

When densFn="gamma" the density used is dgamma. The default value for param is c(1,1).

When densFn="invgamma" or "inverse gamma" the density used is the density of the inverse gamma distribution given by

f(x) = \frac{u^\alpha e^{-u}}{x \Gamma(\alpha)}, % \quad u = \theta/x

for x > 0, \alpha > 0 and \theta > 0. The parameter vector param = c(shape,rate) where shape =\alpha and rate=1/\theta. The default value for param is c(-1,1).

Value

The value of the integral as specified in Details.

Author(s)

David Scott d.scott@auckland.ac.nz, Christine Yang Dong c.dong@auckland.ac.nz

See Also

dghyp, dhyperb, dgamma, dgig

Examples

### Calculate the mean of a generalized hyperbolic distribution
### Compare the use of integration and the formula for the mean
m1 <- momIntegrated("ghyp", param = c(1/2,3,1,1,0), order = 1, about = 0)
m1
ghypMean(c(1/2,3,1,1,0))
### The first moment about the mean should be zero
momIntegrated("ghyp", order = 1, param = c(1/2,3,1,1,0), about = m1)
### The variance can be calculated from the raw moments
m2 <- momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = 0)
m2
m2 - m1^2
### Compare with direct calculation using integration
momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = m1)
momIntegrated("generalized hyperbolic", param = c(1/2,3,1,1,0), order = 2,
              about = m1)
### Compare with use of the formula for the variance
ghypVar(c(1/2,3,1,1,0))

HyperbolicDist documentation built on Nov. 26, 2023, 9:07 a.m.