Moments
Moments
R topics documented:
agostino.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
all.cumulants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
all.moments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
anscombe.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
bonett.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
central2raw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
geary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
jarque.test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
kurtosis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
moment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
raw2central . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
skewness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Index 15
1
2 agostino.test
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:
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
all.cumulants 3
Examples
set.seed(1234)
x = rnorm(1000)
skewness(x)
agostino.test(x)
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
No details are currently described.
Value
A vector matrix or data frame of cumulants. For matrices and data frame, column vectors corre-
spond to different random variables.
Author(s)
Frederick Novomestky <[email protected]>
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
4 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 )
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 mo-
ments 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.
anscombe.test 5
Author(s)
Frederick Novomestky <[email protected]>
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 )
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.
6 bonett.test
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:
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)
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"))
bonett.test 7
Arguments
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
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 Statis-
tics and Data Analysis, 40, 435-445.
See Also
geary
Examples
set.seed(1234)
x = rnorm(1000)
geary(x)
bonett.test(x)
8 central2raw
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 cen-
tral 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 <[email protected]>
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
geary 9
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
10 jarque.test
Examples
set.seed(1234)
geary(rnorm(1000))
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:
Author(s)
Frederick Novomestky <[email protected]>
References
Jarque, C. M., Bera, A. K. (1980) Efficient test for normality, homoscedasticity and serial indepen-
dence of residuals, Economic Letters, Vol. 6 Issue 3, 255-259.
kurtosis 11
Examples
set.seed( 1234 )
x <- rnorm( 1000 )
jarque.test( x )
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))
Description
This function computes the sample moment of specified order.
Usage
moment(x, order = 1, central = FALSE, absolute = FALSE, na.rm = FALSE)
12 raw2central
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)
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 <[email protected]>
skewness 13
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
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
14 skewness
See Also
agostino.test
Examples
set.seed(1234)
skewness(rnorm(1000))
Index
∗ htest
agostino.test, 2
anscombe.test, 5
bonett.test, 6
jarque.test, 10
∗ math
all.cumulants, 3
all.moments, 4
central2raw, 8
jarque.test, 10
raw2central, 12
∗ univar
all.cumulants, 3
all.moments, 4
central2raw, 8
geary, 9
kurtosis, 11
moment, 11
raw2central, 12
skewness, 13
agostino.test, 2, 14
all.cumulants, 3
all.moments, 3, 4, 8, 13
anscombe.test, 5, 11
bonett.test, 6, 9
central2raw, 8, 13
geary, 7, 9, 11
jarque.test, 10
kurtosis, 6, 9, 11
moment, 3, 5, 8, 11, 13
raw2central, 5, 8, 12
skewness, 2, 13
15