param2moment

Author

Tingting Zhan

Introduction

This vignette of package param2moment (CRAN, Github) documents …

Prerequisite

New features are first implemented on Github.

remotes::install_github('tingtingzhan/TukeyGH77')
remotes::install_github('tingtingzhan/param2moment')

And eventually make their way to CRAN.

utils::install.packages('TukeyGH77')
utils::install.packages('param2moment')

Note to Users

Examples in this vignette require that the search path has

library(param2moment)
library(ggplot2)
library(geomtextpath)
library(TukeyGH77)
library(sn)

Introduction

Moments

For random variable X,

Raw Moments

Slot Description
@raw1 \mu = \text{E}(X)
@raw2 \text{E}(X^2)
@raw3 \text{E}(X^3)
@raw4 \text{E}(X^4)

Central Moments

According to Binomial theorem,

Slot Central Moment Value Derivation
0 = \text{E}(X-\mu)
@central2 \sigma^2 = \text{E}(X-\mu)^2 \text{E}(X^2) - \mu^2 \text{E}(X^2) - 2\mu\text{E}(X) + \mu^2
@central3 \text{E}(X-\mu)^3 \text{E}(X^3) - 3\mu\text{E}(X^2) + 2\mu^3 \text{E}(X^3) - 3\mu\text{E}(X^2) + 3\mu^2\text{E}(X) - \mu^3
@central4 \text{E}(X-\mu)^4 \text{E}(X^4) - 4\mu\text{E}(X^3) + 6\mu^2\text{E}(X^2) - 3\mu^4 \text{E}(X^4) - 4\mu\text{E}(X^3) + 6\mu^2 \text{E}(X^2) - 4\mu^3\text{E}(X) + \mu^4

Standardized Moments

Slot Standardized Moment Description
0 = \text{E}(X-\mu)/\sigma
1 = \text{E}(X-\mu)^2/\sigma^2
@standardized3 \text{E}(X-\mu)^3/\sigma^3 skewness
@standardized4 \text{E}(X-\mu)^4/\sigma^4 kurtosis

Location-Scale Transformation

For Y = \text{location} + \text{scale} \cdot X,

\begin{cases} \mu_Y & = \text{location} + \text{scale}\cdot \mu_X\\ \sigma_Y & = \text{scale}\cdot \sigma_X \\ \text{skewness}_Y & = \text{skewness}_X\\ \text{kurtosis}_Y & = \text{kurtosis}_X \end{cases}

Conversion of Parameter and Moment

Normal Distribution

moment_norm(mean = 1.2, sd = .7)
#> Distribution: norm
#> Mean: 1.200
#> Standard Deviation: 0.700
#> Skewness: 0.000
#> (Excess) Kurtosis: 0.000

Skew-Normal Distribution

moment_sn(xi = 2, omega = 1.3, alpha = 3)
#> Distribution: sn
#> Mean: 2.984
#> Standard Deviation: 0.850
#> Skewness: 0.667
#> (Excess) Kurtosis: 0.510
moment2sn(skewness = .3)
#>         xi      omega      alpha 
#> -0.8874593  1.3369901  1.4991756

Skew-t Distribution

moment_st(xi = 2, omega = 1.3, alpha = 3, nu = 6)
#> Distribution: st
#> Mean: 3.133
#> Standard Deviation: 1.119
#> Skewness: 1.666
#> (Excess) Kurtosis: 7.659
moment2st(skewness = .2, kurtosis = .3)
#>         xi      omega      alpha         nu 
#> -0.6627910  1.1615769  0.9752484 31.9777192
moment2st(mean = 1, kurtosis = .3, alpha = 0)
#>         xi      omega         nu 
#>  1.0000017  0.9574701 24.0001063

Tukey’s gh Distribution

Tukey’s g-distribution

moment_GH(A = 3, B = 1.5, g = 0, h = .05)
#> Mean: 3.000
#> Standard Deviation: 1.623
#> Skewness: 0.000
#> (Excess) Kurtosis: 0.821
moment2GH(mean = 1, kurtosis = .3, g = 0)
#>          A          B          h 
#> 1.00001979 0.96685835 0.02199973

Tukey’s h-distribution

moment_GH(A = 3, B = 1.5, g = .7, h = 0)
#> Mean: 3.595
#> Standard Deviation: 2.177
#> Skewness: 2.888
#> (Excess) Kurtosis: 17.791
moment2GH(skewness = .2, h = 0)
#>           A           B           g 
#> -0.03317378  0.99668770  0.06650087

Tukey’s g-and-h Distribution

moment_GH(A = 3, B = 1.5, g = .7, h = .05)
#> Mean: 3.647
#> Standard Deviation: 2.468
#> Skewness: 4.082
#> (Excess) Kurtosis: 47.756
moment2GH(skewness = .2, kurtosis = .3)
#>           A           B           g           h 
#> -0.03065172  0.97137360  0.06145358  0.01708765

Gamma Distribution

Batch Visualization

skw = c(.2, .5, .8)
krt = c(.5, 1, 1.5)

Kurtosis only

Student (1908)-t vs. Tukey’s h

  • R function sn::dst (Azzalini 2023)scale \omega, degree-of-freedom \nu

  • \mu = 0, \sigma = 1, Kurtosis=.5, 1, or 1.5

[R] Student-t and Tukey-h
p1 = moment2param(distname = 'st', MoreArgs = list(alpha = 0), kurtosis = krt) + 
  xlim(-1.5, 1.5) + labs(y = latex2exp::TeX('Student-$t$'))
p2 = moment2param(distname = 'GH', MoreArgs = list(g = 0), kurtosis = krt) + 
  xlim(-1.5, 1.5) + labs(y = latex2exp::TeX('Tukey\'s $h$'))
p1 + p2

Skewness only

Skew-Normal vs. Tukey’s g

  • R function sn::dsnlocation \xi, scale \omega, slant \alpha

  • \mu = 0, \sigma = 1, Skewness=.2, .5, or .8

[R] Skew-Normal and Tukey-g
p1 = moment2param(dist = 'sn', skewness = skw, hjust = .42) + xlim(-2, 2.5) + labs(y = 'Skew-Normal')
p2 = moment2param(dist = 'GH', MoreArgs = list(h = 0), skewness = skw, hjust = .42) + 
  xlim(-2, 2.5) + labs(y = latex2exp::TeX('Tukey\'s $g$'))
p1 + p2

Skewness & Kurtosis

Skew-t vs. Tukey’s g-&-h

  • R function sn::dstlocation \xi, scale \omega, slant \alpha, degree-of-freedom \nu

  • \mu = 0, \sigma = 1, (Skewness, Kurtosis)=(.2,.5), (.5,1), or (.8,1.5)

[R] Skew-t and Tukey-gh
p1 = moment2param(distname = 'st', skewness = skw, kurtosis = krt, hjust = .35) +
  xlim(-2, 2.5) + labs(y = latex2exp::TeX('Skew-$t$'))
p2 = moment2param(distname = 'GH', skewness = skw, kurtosis = krt, hjust = .35) +
  xlim(-2, 2.5) + labs(y = latex2exp::TeX('Tukey\'s $g$-&-$h$'))
p1 + p2

[R] Gamma
moment2param(distname = 'gamma', skewness = skw, kurtosis = 3, hjust = .4) +
  xlim(0, 4) + labs(y = latex2exp::TeX('$gamma$'))

Appendix

Terms and Abbreviations

Term / Abbreviation Description
|> Forward pipe operator introduced in R 4.1.0
all.equal.numeric Test of near equality
CRAN, R The Comprehensive R Archive Network
curve Function plots
.lm.fit Least squares regression, the internal workhorse
mad Median Absolute Deviation
median Median
dnorm, pnorm, qnorm, rnorm Normal Distribution
optim, optimize Optimization
sd Standard Deviation
search Search path
seed Random number generation seed
vuniroot Vectorised one-dimensional root-finding, in package rstpm2

References

Azzalini, Azzalini A. 2023. The R Package sn: The Skew-Normal and Related Distributions Such as the Skew-t and the SUN (Version 2.1.1). Università degli Studi di Padova, Italia. https://cran.r-project.org/package=sn.
Student. 1908. “The Probable Error of a Mean.” Biometrika 6 (1): 1–25.