Moments, cumulants, skewness, kurtosis and related tests

Moments, cumulants, skewness, kurtosis and related tests [R logo]

Help pages for package ‘moments’ version 0.11

agostino.test | D'Agostino test of skewness
all.cumulants | Statistical Cumulants
all.moments | Statistical Moments
anscombe.test | Anscombe-Glynn test of kurtosis
bonett.test | Bonett-Seier test of Geary's kurtosis
central2raw | Central to raw moments
geary | Geary's measure of kurtosis
jarque.test | Jarque-Bera test for normality
kurtosis | Pearson's measure of kurtosis
moment | Statistical Moments
raw2central | Raw to central moments
skewness | Skewness of the sample


D'Agostino test of skewness

Description

Performs D'Agostino test for skewness in normally distributed data.

Usage

agostino.test(x, alternative = c("two.sided", "less", "greater"))

Arguments

x | a numeric vector of data values.
alternative | a character string specifying the alternative hypothesis, must be one of '"two.sided"' (default), '"greater"' or '"less"'. You can specify just the initial letter.

Details

Under the hypothesis of normality, data should be symmetrical (i.e. skewness should be equal to zero). This test has such null hypothesis and is useful to detect a significant skewness in normally distributed data.

Value

A list with class htest containing the following components:

statistic | the list containing skewness estimator and its transformation.
p.value | the p-value for the test.
alternative | a character string describing the alternative hypothesis.
method | a character string indicating what type of test was performed.
data.name | name of the data argument.

Author(s)

Lukasz Komsta

References

D'Agostino, R.B. (1970). Transformation to Normality of the Null Distribution of G1. Biometrika, 57, 3, 679-681.

See Also

skewness

Examples

set.seed(1234)
x = rnorm(1000)
skewness(x)
agostino.test(x)
[Package moments version 0.11 Index]


Statistical Cumulants

Description

This function calculates the cumulants for all orders specified in the given vector, matrix or data frame of raw moments

Usage

all.cumulants(mu.raw)

Arguments

mu.raw A numeric vector, matrix or data frame of raw moments. For a vector, mu.raw[0] is the order 0 raw moment, mu.raw[1] is the order 1 raw moment and so forth. For a matrix or data frame, row vector mu.raw[0,] contains the order 0 raw moments, row vector mu.raw[1,] contains the order 1 raw moments and so forth.

Details

~~ If necessary, more details than the description above ~~

Value

A vector matrix or data frame of cumulants. For matrices and data frame, column vectors correspond to different random variables.

Author(s)

Frederick Novomestky fnovomes@poly.edu

References

Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.

See Also

moment, all.moments

Examples

set.seed(1234)
x <- rnorm(10000)
mu.raw.x <- all.moments( x, order.max=6 )
all.cumulants( mu.raw.x )
M <- matrix( x, nrow=1000, ncol=10 )
mu.raw.M <- all.moments( M, order.max=6 )
all.cumulants( mu.raw.M )
D <- data.frame( M )
mu.raw.D <- all.moments( D, order.max=6 )
all.cumulants( mu.raw.D )


Statistical Moments

Description

This function computes all the sample moments of the chosen type up to a given order.

Usage

all.moments(x, order.max = 2, central = FALSE, absolute = FALSE, na.rm = FALSE)

Arguments

x | A numeric vector, matrix or data frame of data. For matrices and data frames, each column is a random variable
order.max | the maximum order of the moments to be computed with a default value of 2.
central | a logical value, if TRUE, central moments are computed. Otherwise, raw moments are computed
absolute | a logical value, if TRUE, absolute moments are computed. Otherwise, standard moments are computed
na.rm | a logical value, if TRUE, remove NA values. Otherwise, keep NA values

Details

The minimum value for order.max is 2. The function stops running for values less than 2 and the message "maximum order whould be at least 2" is displayed on standard output.

Value

A vector, matrix or data frame of moments depending on the nature of the argument x. If x is a vector, then the value returned is a vector, say mu, where mu[1] is the order 0 moment, mu[2] is the order 1 moment and so forth. If x is a matrix or data frame, then the value returned is a matrix or data frame, respectively. In this case, suppose mu is the value returned. Then, row vector mu[1,] contains the order 0 moments, mu[2,] contains the order 1 moments and so forth.

Author(s)

Frederick Novomestky fnovomes@poly.edu

References

Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.

See Also

moment, raw2central

Examples

set.seed(1234)
x <- rnorm(10000)
all.moments( x, order.max=4 )
all.moments( x, central=TRUE, order.max=4 )
all.moments( x, absolute=TRUE, order.max=4 )
all.moments( x, central=TRUE, absolute=TRUE, order.max=4 )
M <- matrix( x, nrow=1000, ncol=10 )
all.moments( M, order.max=4 )
all.moments( M, central=TRUE, order.max=4 )
all.moments( M, absolute=TRUE, order.max=4 )
all.moments( M, central=TRUE, absolute=TRUE, order.max=4 )
D <- data.frame( M )
all.moments( D, order.max=4 )
all.moments( D, central=TRUE, order.max=4 )
all.moments( D, absolute=TRUE, order.max=4 )
all.moments( D, central=TRUE, absolute=TRUE, order.max=4 )


Anscombe-Glynn test of kurtosis

Description

Performs Anscombe-Glynn test of kurtosis for normal samples

Usage

anscombe.test(x, alternative = c("two.sided", "less", "greater"))

Arguments

x | a numeric vector of data values.
alternative | a character string specifying the alternative hypothesis, must be one of '"two.sided"' (default), '"greater"' or '"less"'. You can specify just the initial letter.

Details

Under the hypothesis of normality, data should have kurtosis equal to 3. This test has such null hypothesis and is useful to detect a significant difference of kurtosis in normally distributed data.

Value

A list with class htest containing the following components:

statistic | the list containing kurtosis estimator and its transformation.
p.value | the p-value for the test.
alternative | a character string describing the alternative hypothesis.
method | a character string indicating what type of test was performed.
data.name | name of the data argument.

Author(s)

Lukasz Komsta

References

Anscombe, F.J., Glynn, W.J. (1983) Distribution of kurtosis statistic for normal statistics. Biometrika, 70, 1, 227-234

See Also

kurtosis

Examples

set.seed(1234)
x = rnorm(1000)
kurtosis(x)
anscombe.test(x)


Bonett-Seier test of Geary's kurtosis

Description

This function performs Bonett-Seier test of Geary's measure of kurtosis for normally distributed data.

Usage

bonett.test(x, alternative = c("two.sided", "less", "greater"))

Arguments

x | a numeric vector of data values.
alternative | a character string specifying the alternative hypothesis, must be one of '"two.sided"' (default), '"greater"' or '"less"'. You can specify just the initial letter.

Details

Under the hypothesis of normality, data should have Geary's kurtosis equal to sqrt(2/pi) (0.7979). This test has such null hypothesis and is useful to detect a significant difference of Geary's kurtosis in normally distributed data.

Value

A list with class htest containing the following components:

statistic | the list containing Geary's kurtosis estimator and its transformation.
p.value | the p-value for the test.
alternative | a character string describing the alternative hypothesis.
method | a character string indicating what type of test was performed.
data.name | name of the data argument.

Author(s)

Lukasz Komsta

References

Bonett, D.G., Seier, E. (2002) A test of normality with high uniform power. Computational Statistics and Data Analysis, 40, 435-445.

See Also

geary

Examples

set.seed(1234)
x = rnorm(1000)
geary(x)
bonett.test(x)


Central to raw moments

Description

This function transforms a vector, matrix or data frame of central moments to a vector, matrix or data frame of raw moments.

Usage

central2raw(mu.central,eta)

Arguments

mu.central | A numeric vector, matrix or data frame of central moments. For a vector, mu.central[0] is the order 0 central moment, mu.central[1] is the order 1 central moment and so forth. For a matrix or data frame, row vector mu.central[0,] contains the order 0 central moments, row vector mu.central[1,] contains the order 1 central moments and so forth.
eta | A numeric vector of sample mean or expected values

Value

A vector matrix or data frame of raw moments. For matrices and data frame, column vectors correspond to different random variables.

Author(s)

Frederick Novomestky fnovomes@poly.edu

References

Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.

See Also

moment, all.moments, raw2central

Examples

set.seed(1234)
x <- rnorm(10000)
mu.raw.x <- all.moments( x, order.max=4 )
eta.x <- mu.raw.x[2]
mu.central.x <- all.moments( x, central=TRUE, order.max=4 )
central2raw( mu.central.x, eta.x )
mu.raw.x
M <- matrix( x, nrow=1000, ncol=10 )
mu.raw.M <- all.moments( M, order.max=4 )
eta.M <- mu.raw.M[2,]
mu.central.M <- all.moments( M, central=TRUE, order.max=4 )
central2raw( mu.central.M, eta.M )
mu.raw.M
D <- data.frame( M )
mu.raw.D <- all.moments( D, order.max=4 )
eta.D <- mu.raw.D[2,]
mu.central.D <- all.moments( D, central=TRUE, order.max=4 )
central2raw( mu.central.D, eta.D )
mu.raw.D


Geary's measure of kurtosis

Description

This function computes an estimator of Geary's measure of kurtosis.

Usage

geary(x, na.rm = FALSE)

Arguments

x | a numeric vector, matrix or data frame.
na.rm | logical. Should missing values be removed?

Details

The Geary's kurtosis is computed by dividing average difference between observation and the mean by standard deviation of the sample.

Author(s)

Lukasz Komsta

References

Geary, R.C. (1936). Moments of the ratio of the mean deviation to the standard deviation for normal samples. Biometrika, 28, 295-307.

See Also

kurtosis, bonett.test

Examples

set.seed(1234)
geary(rnorm(1000))


Jarque-Bera test for normality

Description

This function performs the Jarque-Bera test on the given data sample to determine if the data are sample drawn from a normal population.

Usage

jarque.test(x)

Arguments

x a numeric vector of data

Details

Under the hypothesis of normality, data should be symmetrical (i.e. skewness should be equal to zero) and have skewness chose to three. The Jarque-Bera statistic is chi-square distributed with two degrees of freedom.

Value

A list with class htest containing the following components:

statistic | the list containing the Jarque-Bera statistic
p.value | the p-value for the test.
alternative | a character string describing the alternative hypothesis.
method | a character string indicating what type of test was performed.
data.name | name of the data argument.

Author(s)

Frederick Novomestky fnovomes@poly.edu

References

Jarque, C. M., Bera, A. K. (1980) Efficient test for normality, homoscedasticity and serial independence of residuals, Economic Letters, Vol. 6 Issue 3, 255-259.

Examples

set.seed( 1234 )
x <- rnorm( 1000 )
jarque.test( x )


Pearson's measure of kurtosis

Description

This function computes the estimator of Pearson's measure of kurtosis.

Usage

kurtosis(x, na.rm = FALSE)

Arguments

x | a numeric vector, matrix or data frame.
na.rm | logical. Should missing values be removed?

Author(s)

Lukasz Komsta

See Also

geary, anscombe.test

Examples

set.seed(1234)
kurtosis(rnorm(1000))


Statistical Moments

Description

This function computes the sample moment of specified order.

Usage

moment(x, order = 1, central = FALSE, absolute = FALSE, na.rm = FALSE)

Arguments

x | a numeric vector of data.
order | order of the moment to be computed
central | a logical value - if central moments are to be computed.
absolute | a logical value - if absolute moments are to be computed.
na.rm | a logical value - remove NA values?

Author(s)

Lukasz Komsta

Examples

set.seed(1234)
x <- rnorm(10)
moment(x)
moment(x,order=3,absolute=TRUE)


Raw to central moments

Description

This function transforms a vector, matrix or data frame of raw moments to a vector, matrix or data frame of central moments.

Usage

raw2central(mu.raw)

Arguments

mu.raw A numeric vector, matrix or data frame of raw moments. For a vector, mu.raw[0] is the order 0 raw moment, mu.raw[1] is the order 1 raw moment and so forth. For a matrix or data frame, row vector mu.raw[0,] contains the order 0 raw moments, row vector mu.raw[1,] contains the order 1 raw moments and so forth.

Value

A vector matrix or data frame of central moments. For matrices and data frame, column vectors correspond to different random variables.

Author(s)

Frederick Novomestky fnovomes@poly.edu

References

Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.

See Also

moment, all.moments, central2raw

Examples

set.seed(1234)
x <- rnorm(10000)
mu.raw.x <- all.moments( x, order.max=4 )
mu.central.x <- all.moments( x, central=TRUE, order.max=4 )
raw2central( mu.raw.x )
mu.central.x
M <- matrix( x, nrow=1000, ncol=10 )
mu.raw.M <- all.moments( M, order.max=4 )
mu.central.M <- all.moments( M, central=TRUE, order.max=4 )
raw2central( mu.raw.M )
mu.central.M
D <- data.frame( M )
mu.raw.D <- all.moments( D, order.max=4 )
mu.central.D <- all.moments( D, central=TRUE, order.max=4 )
raw2central( mu.raw.D )
mu.central.D


Skewness of the sample

Description

This function computes skewness of given data.

Usage

skewness(x, na.rm = FALSE)

Arguments

x | a numeric vector, matrix or data frame.
na.rm | logical. Should missing values be removed?

Author(s)

Lukasz Komsta

See Also

agostino.test

Examples

set.seed(1234)
skewness(rnorm(1000))