Title: | Moments, Cumulants, Skewness, Kurtosis and Related Tests |
---|---|
Description: | Functions to calculate: moments, Pearson's kurtosis, Geary's kurtosis and skewness; tests related to them (Anscombe-Glynn, D'Agostino, Bonett-Seier). |
Authors: | Lukasz Komsta <[email protected]>, Frederick Novomestky <[email protected]> |
Maintainer: | Lukasz Komsta <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.14.1 |
Built: | 2024-12-16 06:49:11 UTC |
Source: | CRAN |
Performs D'Agostino test for skewness in normally distributed data.
agostino.test(x, alternative = c("two.sided", "less", "greater"))
agostino.test(x, alternative = c("two.sided", "less", "greater"))
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. |
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.
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. |
Lukasz Komsta
D'Agostino, R.B. (1970). Transformation to Normality of the Null Distribution of G1. Biometrika, 57, 3, 679-681.
set.seed(1234) x = rnorm(1000) skewness(x) agostino.test(x)
set.seed(1234) x = rnorm(1000) skewness(x) agostino.test(x)
This function calculates the cumulants for all orders specified in the given vector, matrix or data frame of raw moments
all.cumulants(mu.raw)
all.cumulants(mu.raw)
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. |
No details are currently described.
A vector matrix or data frame of cumulants. For matrices and data frame, column vectors correspond to different random variables.
Frederick Novomestky [email protected]
Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.
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 )
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 )
This function computes all the sample moments of the chosen type up to a given order.
all.moments(x, order.max = 2, central = FALSE, absolute = FALSE, na.rm = FALSE)
all.moments(x, order.max = 2, central = FALSE, absolute = FALSE, na.rm = FALSE)
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 |
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.
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.
Frederick Novomestky [email protected]
Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.
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 )
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 )
Performs Anscombe-Glynn test of kurtosis for normal samples
anscombe.test(x, alternative = c("two.sided", "less", "greater"))
anscombe.test(x, alternative = c("two.sided", "less", "greater"))
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. |
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.
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. |
Lukasz Komsta
Anscombe, F.J., Glynn, W.J. (1983) Distribution of kurtosis statistic for normal statistics. Biometrika, 70, 1, 227-234
set.seed(1234) x = rnorm(1000) kurtosis(x) anscombe.test(x)
set.seed(1234) x = rnorm(1000) kurtosis(x) anscombe.test(x)
This function performs Bonett-Seier test of Geary's measure of kurtosis for normally distributed data.
bonett.test(x, alternative = c("two.sided", "less", "greater"))
bonett.test(x, alternative = c("two.sided", "less", "greater"))
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. |
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.
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. |
Lukasz Komsta
Bonett, D.G., Seier, E. (2002) A test of normality with high uniform power. Computational Statistics and Data Analysis, 40, 435-445.
set.seed(1234) x = rnorm(1000) geary(x) bonett.test(x)
set.seed(1234) x = rnorm(1000) geary(x) bonett.test(x)
This function transforms a vector, matrix or data frame of central moments to a vector, matrix or data frame of raw moments.
central2raw(mu.central,eta)
central2raw(mu.central,eta)
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 |
A vector matrix or data frame of raw moments. For matrices and data frame, column vectors correspond to different random variables.
Frederick Novomestky [email protected]
Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.
moment
,
all.moments
,
raw2central
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
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
This function computes an estimator of Geary's measure of kurtosis.
geary(x, na.rm = FALSE)
geary(x, na.rm = FALSE)
x |
a numeric vector, matrix or data frame. |
na.rm |
logical. Should missing values be removed? |
The Geary's kurtosis is computed by dividing average difference between observation and the mean by standard deviation of the sample.
Lukasz Komsta
Geary, R.C. (1936). Moments of the ratio of the mean deviation to the standard deviation for normal samples. Biometrika, 28, 295-307.
set.seed(1234) geary(rnorm(1000))
set.seed(1234) geary(rnorm(1000))
This function performs the Jarque-Bera test on the given data sample to determine if the data are sample drawn from a normal population.
jarque.test(x)
jarque.test(x)
x |
a numeric vector of data |
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.
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. |
Frederick Novomestky [email protected]
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.
set.seed( 1234 ) x <- rnorm( 1000 ) jarque.test( x )
set.seed( 1234 ) x <- rnorm( 1000 ) jarque.test( x )
This function computes the estimator of Pearson's measure of kurtosis.
kurtosis(x, na.rm = FALSE)
kurtosis(x, na.rm = FALSE)
x |
a numeric vector, matrix or data frame. |
na.rm |
logical. Should missing values be removed? |
Lukasz Komsta
set.seed(1234) kurtosis(rnorm(1000))
set.seed(1234) kurtosis(rnorm(1000))
This function computes the sample moment of specified order.
moment(x, order = 1, central = FALSE, absolute = FALSE, na.rm = FALSE)
moment(x, order = 1, central = FALSE, absolute = FALSE, na.rm = FALSE)
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? |
Lukasz Komsta
set.seed(1234) x <- rnorm(10) moment(x) moment(x,order=3,absolute=TRUE)
set.seed(1234) x <- rnorm(10) moment(x) moment(x,order=3,absolute=TRUE)
This function transforms a vector, matrix or data frame of raw moments to a vector, matrix or data frame of central moments.
raw2central(mu.raw)
raw2central(mu.raw)
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. |
A vector matrix or data frame of central moments. For matrices and data frame, column vectors correspond to different random variables.
Frederick Novomestky [email protected]
Papoulis, A., Pillai, S. U. (2002) Probability, Random Variables and Stochastic Processes, Fourth Edition, McGraw-Hill, New York, 146-147.
moment
,
all.moments
,
central2raw
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
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
This function computes skewness of given data.
skewness(x, na.rm = FALSE)
skewness(x, na.rm = FALSE)
x |
a numeric vector, matrix or data frame. |
na.rm |
logical. Should missing values be removed? |
Lukasz Komsta
set.seed(1234) skewness(rnorm(1000))
set.seed(1234) skewness(rnorm(1000))