DescTools (version 0.99.8.1)

Measures of Shape: Skewness and Kurtosis

Description

Skew computes the skewness, Kurt the kurtosis of the values in x.

Usage

Skew(x, na.rm = FALSE, method = 3, conf.level = NA, type = "bca", R = 1000)

Kurt(x, na.rm = FALSE, method = 3, conf.level = NA, type = "bca", R = 1000)

Arguments

x
a numeric vector, matrix or data frame. An object which is not a vector, matrix or data frame is coerced (if possible) by as.vector.
na.rm
logical, indicating whether NA values should be stripped before the computation proceeds. Defaults to FALSE.
method
integer out of 1, 2 or 3. Default ist 3. See Details.
conf.level
confidence level of the interval. If set to NA (which is the default) no confidence interval will be calculated.
type
The type of confidence interval required. The value should be any subset of the values "norm", "basic", "stud", "perc", "bca") or simply "all" which will compute all five
R
The number of bootstrap replicates. Usually this will be a single positive integer. For importance resampling, some resamples may use one set of weights and others use a different set of weights. In this case R would be a vector of inte

Value

  • For a data frame or for a matrix, a named vector with the appropriate method being applied column by column.

Details

If x is a matrix or a data frame, a vector of the skewness, resp. kurtosis, of the columns is returned. If na.rm is TRUE then missing values are removed before computation proceeds. The type of skewness can either be: type = 1: g_1 = m_3 / m_2^(3/2) type = 2: G_1 = g_1 * sqrt(n(n-1)) / (n-2) type = 3: b_1 = m_3 / s^3 = g_1 ((n-1)/n)^(3/2) The type of kurtosis can either be: type = 1: g_2 = m_4 / m_2^2 - 3 type = 2: G_2 = ((n+1) g_2 + 6) * (n-1) / ((n-2)(n-3)) type = 3: b_2 = m_4 / s^4 - 3 = (g_2 + 3) (1 - 1/n)^2 - 3 type = 1 is the typical definition used in many older textbooks. type = 2 is used in SAS and SPSS. type = 3 is used in MINITAB and BMDP. Skew and Kurtosis are comparably fast, as the expensive sums are coded in C.

References

Cramer, D. (1997): Basic Statistics for Social Research Routledge. Joanes, D. N., Gill, C. A. (1998): Comparing measures of sample skewness and Kurt. The Statistician, 47, 183-189.

See Also

mean, sd, similar code in library(e1071)

Examples

Run this code
Skew(d.pizza$price, na.rm=TRUE)
Kurt(d.pizza$price, na.rm=TRUE)

# use sapply to calculate skewness for a data.frame
sapply(d.pizza[,c("temperature","price","delivery_min")], Skew, na.rm=TRUE)

# or apply to do that columnwise with a matrix
apply(as.matrix(d.pizza[,c("temperature","price","delivery_min")]), 2, Skew, na.rm=TRUE)

Run the code above in your browser using DataLab