Learn R Programming

descstat (version 0.1-2)

univariate: Functions to compute statistics on univariate distributions

Description

descstat provide functions to compute statistics on an univariate distribution. This includes central tendency, dispersion, shape and concentration.

Usage

variance(x, ...)

gmean(x, r = 1, ...)

gini(x, ...)

stdev(x, ...)

madev(x, ...)

modval(x, ...)

medial(x, ...)

kurtosis(x, ...)

skewness(x, ...)

# S3 method for default variance(x, w = NULL, ...)

# S3 method for default gmean(x, r = 1, ...)

# S3 method for default stdev(x, w = NULL, ...)

# S3 method for default madev(x, w = NULL, center = c("median", "mean"), ...)

# S3 method for default skewness(x, ...)

# S3 method for default kurtosis(x, ...)

# S3 method for freq_table mean(x, ...)

# S3 method for freq_table gmean(x, r = 1, ...)

# S3 method for freq_table variance(x, ...)

# S3 method for freq_table stdev(x, ...)

# S3 method for freq_table skewness(x, ...)

# S3 method for freq_table kurtosis(x, ...)

# S3 method for freq_table madev(x, center = c("median", "mean"), ...)

# S3 method for freq_table modval(x, ...)

# S3 method for freq_table quantile(x, y = c("value", "mass"), probs = c(0.25, 0.5, 0.75), ...)

# S3 method for freq_table median(x, ..., y = c("value", "mass"))

# S3 method for freq_table medial(x, ...)

# S3 method for freq_table gini(x, ...)

# S3 method for cont_table modval(x, ...)

# S3 method for cont_table gini(x, ...)

# S3 method for cont_table skewness(x, ...)

# S3 method for cont_table kurtosis(x, ...)

# S3 method for cont_table madev(x, center = c("median", "mean"), ...)

# S3 method for cont_table mean(x, ...)

# S3 method for cont_table variance(x, ...)

# S3 method for cont_table stdev(x, ...)

Arguments

x

a series or a freq_table or a cont_table object,

...

further arguments,

r

the order of the mean for the gmean function,

w

a vector of weights,

center

the center value used to compute the mean absolute deviations, one of "median" or "mean",

y

for the quantile method, one of "value" or "mass",

probs

the probabilities for which the quantiles have to be computed.

Value

a numeric or a tibble.

Details

The following functions are provided:

  • central tendency: mean, median, medial, modval (for the mode),

  • dispersion: variance, stdev, maddev (for mean absolute deviation) and quantile,

  • shape: skewness and kurtosis,

  • concentration: gini.

When a generic function exists in base R (or in the stats package), methods are provided for freq_table or cont_table, this is a case for mean, median and quantile. When a function exists, but is not generic, we provide a generic and relevant methods using different names (stdev, variance and madev instead respectively of sd, var and mad). Finally some function don't exist in base R and recommended packages, we therefore provide a modval function to compute the mode, gini for the Gini concentration index, skewness and kurtosis for Fisher's shape statistics and gmean for generalized means (which include the geometric, the quadratic and the harmonic means).

madev has a center argument which indicates whether the deviations should be computed respective to the mean or to the median.

gmean has a r argument: values of -1, 0, 1 and 2 lead respectively to the harmonic, geometric, arithmetic and quadratic means.

Examples

Run this code
# NOT RUN {
library("dplyr")
z <- wages %>% freq_table(wage)
z %>% median
# the medial is the 0.5 quantile of the mass of the distribution
z %>% medial
# the modval function returns the mode, it is a one line tibble
z %>% modval
z %>% quantile(probs = c(0.25, 0.5, 0.75))
# quantiles can compute for the frequency (the default) or the mass
# of the series
z %>% quantile(y = "mass", probs = c(0.25, 0.5, 0.75))
# univariate statistics can be computed on the joint, marginal or
# conditional distributions for cont_table objects
wages %>% cont_table(wage, size) %>% joint
wages %>% cont_table(wage, size) %>% marginal(size) %>% mean
wages %>% cont_table(wage, size) %>% conditional(size) %>% mean

# }

Run the code above in your browser using DataLab