Learn R Programming

propagate (version 1.3-0)

moments: Skewness and (excess) Kurtosis of a vector of values or of the columns of a matrix/data frame

Description

These functions calculate skewness and excess kurtosis of a vector of values, or column-wise for a matrix or data frame. They were adapted from the package 'moments'.

Usage

skewness(x, na.rm = FALSE) 
kurtosis(x, na.rm = FALSE)

Value

The skewness/kurtosis value of a vector, or a vector with one value per column of a matrix or data frame.

Arguments

x

a numeric vector, matrix or data frame.

na.rm

logical. Should missing values be removed?

Author

Andrej-Nikolai Spiess

Details

The formulas use the biased (\(1/n\)) sample moments, without small-sample correction, as in package 'moments' (other software may use bias-corrected versions):
Skewness: $$\frac{\frac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^3}{\left(\frac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^2\right)^{3/2}}$$

(excess) Kurtosis: $$\frac{\frac{1}{n} \sum_{i=1}^n (x_i - \overline{x})^4}{\left(\frac{1}{n} \sum_{i=1}^n (x_i - \overline{x})^2\right)^2} - 3$$

Examples

Run this code
X <- rnorm(100, 20, 2)
skewness(X)
kurtosis(X)

Run the code above in your browser using DataLab