Type: Package
Title: Raw, Central and Standardized Moments of Parametric Distributions
Version: 0.1.3
Date: 2025-03-15
Description: To calculate the raw, central and standardized moments from distribution parameters. To solve the distribution parameters based on user-provided mean, standard deviation, skewness and kurtosis. Normal, skew-normal, skew-t and Tukey g-&-h distributions are supported, for now.
License: GPL-2
Encoding: UTF-8
Language: en-US
Depends: R (≥ 4.4.0)
Imports: methods
Suggests: sn
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-03-15 18:17:07 UTC; tingtingzhan
Author: Tingting Zhan ORCID iD [aut, cre]
Maintainer: Tingting Zhan <tingtingzhan@gmail.com>
Repository: CRAN
Date/Publication: 2025-03-15 22:10:05 UTC

Raw, Central and Standardized Moments, and other Distribution Characteristics

Description

Up to 4th raw \text{E}(Y^n), central \text{E}[(Y-\mu)^n] and standardized moments \text{E}[(Y-\mu)^n/\sigma^n] of the random variable

Y = (X - \text{location})/\text{scale}

Also, the mean, standard deviation, skewness and excess kurtosis of the random variable X.

Details

For Y = (X - \text{location})/\text{scale}, let \mu = \text{E}(Y), then, according to Binomial theorem, the 2nd to 4th central moments of Y are,

\text{E}[(Y-\mu)^2] = \text{E}(Y^2) - 2\mu \text{E}(Y) + \mu^2 = \text{E}(Y^2) - \mu^2

\text{E}[(Y-\mu)^3] = \text{E}(Y^3) - 3\mu \text{E}(Y^2) + 3\mu^2 \text{E}(Y) - \mu^3 = \text{E}(Y^3) - 3\mu \text{E}(Y^2) + 2\mu^3

\text{E}[(Y-\mu)^4] = \text{E}(Y^4) - 4\mu \text{E}(Y^3) + 6\mu^2 \text{E}(Y^2) - 4\mu^3 \text{E}(Y) + \mu^4 = \text{E}(Y^4) - 4\mu \text{E}(Y^3) + 6\mu^2 \text{E}(Y^2) - 3\mu^4

The distribution characteristics of Y are,

\mu_Y = \mu

\sigma_Y = \sqrt{\text{E}[(Y-\mu)^2]}

\text{skewness}_Y = \text{E}[(Y-\mu)^3] / \sigma^3_Y

\text{kurtosis}_Y = \text{E}[(Y-\mu)^4] / \sigma^4_Y - 3

The distribution characteristics of X are \mu_X = \text{location} + \text{scale}\cdot \mu_Y, \sigma_X = \text{scale}\cdot \sigma_Y, \text{skewness}_X = \text{skewness}_Y, and \text{kurtosis}_X = \text{kurtosis}_Y.

Slots

distname

character scalar, name of distribution, e.g., 'norm' for normal, 'sn' for skew-normal, 'st' for skew-t, and 'GH' for Tukey g-&-h distribution, following the nomenclature of dnorm, dsn, dst and QuantileGH::dGH

location,scale

numeric scalars or vectors, location and scale parameters

mu

numeric scalar or vector, 1st raw moment \mu = \text{E}(Y). Note that the 1st central moment \text{E}(Y-\mu) and standardized moment \text{E}(Y-\mu)/\sigma are both 0.

raw2,raw3,raw4

numeric scalars or vectors, 2nd or higher raw moments \text{E}(Y^n), n\geq 2

central2,central3,central4

numeric scalars or vectors, 2nd or higher central moments, \sigma^2 = \text{E}[(Y-\mu)^2] and \text{E}[(Y-\mu)^n], n\geq 3

standardized3,standardized4

numeric scalars or vectors, 3rd or higher standardized moments, skewness \text{E}[(Y-\mu)^3]/\sigma^3 and kurtosis \text{E}[(Y-\mu)^4]/\sigma^4. Note that the 2nd standardized moment is 1

Note

Potential name clash with function e1071::moment.


Solve Tukey g-&-h Parameters from Moments

Description

Solve Tukey g-, h- and g-&-h distribution parameters from mean, standard deviation, skewness and kurtosis.

Usage

moment2GH(mean = 0, sd = 1, skewness, kurtosis)

moment2GH_h_demo(sd = 1, kurtosis)

moment2GH_g_demo(mean = 0, sd = 1, skewness)

Arguments

mean

numeric scalar, mean \mu, default value 0

sd

numeric scalar, standard deviation \sigma, default value 1

skewness

numeric scalar

kurtosis

numeric scalar

Details

Function moment2GH() solves the location A, scale B, skewness g and elongation h parameters of Tukey g-&-h distribution, from user-specified mean \mu (default 0), standard deviation \sigma (default 1), skewness and kurtosis.

An educational and demonstration function moment2GH_h_demo() solves (B, h) parameters of Tukey h-distribution, from user-specified \sigma and kurtosis. This is a non-skewed distribution, thus the location parameter A=\mu=0, and the skewness parameter g=0.

An educational and demonstration function moment2GH_g_demo() solves (A, B, g) parameters of Tukey g-distribution, from user-specified \mu, \sigma and skewness. For this distribution, the elongation parameter h=0.

Value

Function moment2GH() returns a length-4 numeric vector (A, B, g, h).

Function moment2GH_h_demo() returns a length-2 numeric vector (B, h).

Function moment2GH_g_demo() returns a length-3 numeric vector (A, B, g).

Examples

moment2GH(skewness = .2, kurtosis = .3)

moment2GH_h_demo(kurtosis = .3)

moment2GH_g_demo(skewness = .2)


Moment to Parameters: A Batch Process

Description

Converts multiple sets of moments to multiple sets of distribution parameters.

Usage

moment2param(distname, FUN = paste0("moment2", distname), ...)

Arguments

distname

character scalar, distribution name. Currently supported are 'GH' for Tukey g-&-h distribution, 'sn' for skew-normal distribution and 'st' for skew-t distribution

FUN

name or character scalar, (name of) function used to solve the distribution parameters from moments. Default is paste0('moment2', distname), e.g., moment2GH will be used for distname = 'GH'. To use one of the educational functions, specify FUN = moment2GH_g_demo or FUN = 'moment2GH_g_demo'.

...

numeric scalars, some or all of mean, sd, skewness and kurtosis (length will be recycled).

Value

Function moment2param() returns a list of numeric vectors.

Examples

skw = c(.2, .5, .8)
krt = c(.5, 1, 1.5)
moment2param(distname = 'GH', skewness = skw, kurtosis = krt)
moment2param(distname = 'st', skewness = skw, kurtosis = krt)


Solve Skew-Normal Parameters from Moments

Description

Solve skew-normal parameters from mean, standard deviation and skewness.

Usage

moment2sn(mean = 0, sd = 1, skewness)

Arguments

mean

numeric scalar, mean \mu, default value 0

sd

numeric scalar, standard deviation \sigma, default value 1

skewness

numeric scalar

Details

Function moment2sn() solves the location \xi, scale \omega and slant \alpha parameters of skew-normal distribution, from user-specified mean \mu (default 0), standard deviation \sigma (default 1) and skewness.

Value

Function moment2sn() returns a length-3 numeric vector (\xi, \omega, \alpha).

Examples

moment2sn(skewness = .3)


Solve Skew-t Parameters from Moments

Description

Solve skew-t parameters from mean, standard deviation, skewness and kurtosis.

Usage

moment2st(mean = 0, sd = 1, skewness, kurtosis)

moment2t_demo(sd = 1, kurtosis)

Arguments

mean

numeric scalar, mean \mu, default value 0

sd

numeric scalar, standard deviation \sigma, default value 1

skewness

numeric scalar

kurtosis

numeric scalar

Details

Function moment2st() solves the location \xi, scale \omega, slant \alpha and degree of freedom \nu parameters of skew-t distribution, from user-specified mean \mu (default 0), standard deviation \sigma (default 1), skewness and kurtosis.

An educational and demonstration function moment2t_demo solves (\omega, \nu) parameters of t-distribution, from user-specified \sigma and kurtosis. This is a non-skewed distribution, thus the location parameter \xi=\mu=0, and the slant parameter \alpha=0.

Value

Function moment2st() returns a length-4 numeric vector (\xi, \omega, \alpha, \nu).

Function moment2t_demo() returns a length-2 numeric vector (\omega, \nu).

Examples

moment2st(skewness = .2, kurtosis = .3)

moment2t_demo(kurtosis = .3)


Moments of Tukey g-&-h Distribution

Description

Moments of Tukey g-&-h distribution.

Usage

moment_GH(A = 0, B = 1, g = 0, h = 0)

Arguments

A

numeric scalar or vector, location parameter A

B

numeric scalar or vector, scale parameter B

g

numeric scalar or vector, skewness parameter g

h

numeric scalar or vector, elongation parameter h

Value

Function moment_GH() returns a moment object.

References

Raw moments of Tukey g-&-h distribution: doi:10.1002/9781118150702.ch11

Examples

A = 3; B = 1.5; g = .7; h = .01
moment_GH(A = A, B = B, g = 0, h = h)
moment_GH(A = A, B = B, g = g, h = 0)
moment_GH(A = A, B = B, g = g, h = h)


Moments of Normal Distribution

Description

Moments of normal distribution, parameter nomenclature follows dnorm function.

Usage

moment_norm(mean = 0, sd = 1)

Arguments

mean

numeric scalar or vector, mean parameter \mu

sd

numeric scalar or vector, standard deviation \sigma

Value

Function moment_norm() returns a moment object.

Examples

moment_norm(mean = 1.2, sd = .7)


Moments of Skew-Normal Distribution

Description

Moments of skew-normal distribution, parameter nomenclature follows dsn function.

Usage

moment_sn(xi = 0, omega = 1, alpha = 0)

Arguments

xi

numeric scalar or vector, location parameter \xi

omega

numeric scalar or vector, scale parameter \omega

alpha

numeric scalar or vector, slant parameter \alpha

Value

Function moment_sn() returns a moment object.

Examples

xi = 2; omega = 1.3; alpha = 3
moment_sn(xi, omega, alpha)
curve(sn::dsn(x, xi = 2, omega = 1.3, alpha = 3), from = 0, to = 6)


Moments of Skew-t Distribution

Description

Moments of skew-t distribution, parameter nomenclature follows dst function.

Usage

moment_st(xi = 0, omega = 1, alpha = 0, nu = Inf)

Arguments

xi

numeric scalar or vector, location parameter \xi

omega

numeric scalar or vector, scale parameter \omega

alpha

numeric scalar or vector, slant parameter \alpha

nu

numeric scalar or vector, degree of freedom \nu

Value

Function moment_st() returns a moment object.

References

Raw moments of skew-t: https://arxiv.org/abs/0911.2342

Examples

xi = 2; omega = 1.3; alpha = 3; nu = 6
curve(sn::dst(x, xi = xi, omega = omega, alpha = alpha, nu = nu), from = 0, to = 6)
moment_st(xi, omega, alpha, nu)


Show moment

Description

Print S4 object moment in a pretty manner.

Usage

## S4 method for signature 'moment'
show(object)

Arguments

object

a moment object

Value

The show method for moment object does not have a returned value.