Moments Using Integration
Calculates moments and absolute moments about a given location for any given distribution.
momIntegrated(densFn = "ghyp", param = NULL, order, about = 0, absolute = FALSE, ...)
densFn |
Character. The name of the density function whose moments are to be calculated. See Details. |
param |
Numeric. A vector giving the parameter values for the
distribution specified by |
order |
Numeric. The order of the moment or absolute moment to be calculated. |
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 |
... |
Passes arguments to |
Denote the density function by f. Then if
order
=k and about
=a,
momIntegrated
calculates
integral_{-infinity}^infinity (x - a)^k f(x) dx
when absolute = FALSE
and
integral_{-infinity}^infinity |x - a|^k f(x) dx
when absolute = TRUE
.
The name of the density function must be supplied as the characters of
the root for that density (e.g. norm
, ghyp
).
When densFn="ghyp"
, densFn="hyperb"
,
densFn="gig"
or densFn = "vg"
, the relevant package must
be loaded or an error will result.
When densFn="invgamma"
or "inverse gamma"
the
density used is the density of the inverse gamma distribution given by
f(x) = u^alpha exp(-u)/(x Gamma(alpha)), 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)
.
The value of the integral as specified in Details.
David Scott d.scott@auckland.ac.nz, Christine Yang Dong c.dong@auckland.ac.nz, Xinxing Li xli053@aucklanduni.ac.nz
require(GeneralizedHyperbolic) ### Calculate the mean of a generalized hyperbolic distribution ### Compare the use of integration and the formula for the mean m1 <- momIntegrated("ghyp", param = c(0, 1, 3, 1, 1 / 2), order = 1, about = 0) m1 ghypMean(param = c(0, 1, 3, 1, 1 / 2)) ### The first moment about the mean should be zero momIntegrated("ghyp", order = 1, param = c(0, 1, 3, 1, 1 / 2), about = m1) ### The variance can be calculated from the raw moments m2 <- momIntegrated("ghyp", order = 2, param = c(0, 1, 3, 1, 1 / 2), about = 0) m2 m2 - m1^2 ### Compare with direct calculation using integration momIntegrated("ghyp", order = 2, param = c(0, 1, 3, 1, 1 / 2), about = m1) momIntegrated("ghyp", param = c(0, 1, 3, 1, 1 / 2), order = 2, about = m1) ### Compare with use of the formula for the variance ghypVar(param = c(0, 1, 3, 1, 1 / 2))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.