ineqpy._statistics

Low level desciptive statistics.

References

  1. http://people.ds.cam.ac.uk/fanf2/hermes/doc/antiforgery/stats.pdf

  2. https://en.wikipedia.org/wiki/Weighted_arithmetic_mean #Weighted_sample_variance

  3. https://en.wikipedia.org/wiki/Algorithms%5Ffor%5Fcalculating%5Fvariance #Weighted_incremental_algorithm

Module Contents

Functions

c_moment([variable, weights, order, param, ddof])

Calculate central momment.

percentile(→ float)

Calculate the percentile.

std_moment([variable, weights, param, order, ddof])

Calculate the standarized moment.

mean([variable, weights])

Calculate the mean of variable given weights.

var([variable, weights, ddof])

Calculate the population variance of variable given weights.

coef_variation([variable, weights])

Calculate the coefficient of variation.

kurt([variable, weights])

Calculate the asymmetry coefficient.

skew([variable, weights])

Return the asymmetry coefficient of a sample.

wvar(x, w, kind, out)

Calculate weighted variance of X.

wcov(x, y, w, kind, out)

Compute weighted covariance between x and y.

online_kurtosis(x, w, out)

Online kurtosis.

Mk(x, w, k, out)

Calculate Mk.

ineqpy._statistics.c_moment(variable=None, weights=None, order=2, param=None, ddof=0)[source]

Calculate central momment.

Calculate the central moment of x with respect to param of order n, given the weights w.

Parameters:
variable1d-array

Variable

weights1d-array

Weights

orderint, optional

Moment order, 2 by default (variance)

paramint or array, optional

Parameter for which the moment is calculated, the default is None, implies use the mean.

ddofint, optional

Degree of freedom, zero by default.

Returns:
central_momentfloat

Notes

  • The cmoment of order 1 is 0

  • The cmoment of order 2 is the variance.

Source : https://en.wikipedia.org/wiki/Moment_(mathematics)

ineqpy._statistics.percentile(variable, weights, percentile=50, interpolation='lower') float[source]

Calculate the percentile.

Parameters:
variablestr or array
weightsstr or array
percentileint or list

Percentile level, if pass 50 we get the median.

interpolation{‘lower’, ‘higher’, ‘midpoint’}, optional

Select interpolation method.

Returns:
percentilefloat
ineqpy._statistics.std_moment(variable=None, weights=None, param=None, order=3, ddof=0)[source]

Calculate the standarized moment.

Calculate the standarized moment of order c for the variable` x` with respect to c.

Parameters:
variable1d-array

Random Variable

weights1d-array, optional

Weights or probability

orderint, optional

Order of Moment, three by default

paramint or float or array, optional

Central trend, default is the mean.

ddofint, optional

Degree of freedom.

Returns:
std_momentfloat

Returns the standardized n order moment.

References

ineqpy._statistics.mean(variable=None, weights=None)[source]

Calculate the mean of variable given weights.

Parameters:
variablearray-like or str

Variable on which the mean is estimated.

weightsarray-like or str

Weights of the x variable.

Returns:
meanarray-like or float
ineqpy._statistics.var(variable=None, weights=None, ddof=0)[source]

Calculate the population variance of variable given weights.

Parameters:
variable1d-array or pd.Series or pd.DataFrame

Variable on which the quasivariation is estimated

weights1d-array or pd.Series or pd.DataFrame

Weights of the variable.

Returns:
variance1d-array or pd.Series or float

Estimation of quasivariance of variable

Notes

If stratificated sample must pass with groupby each strata.

References

Moment (mathematics). (2017, May 6). In Wikipedia, The Free Encyclopedia. Retrieved 14:40, May 15, 2017, from https://en.wikipedia.org/w/index.php?title=Moment_(mathematics)

ineqpy._statistics.coef_variation(variable=None, weights=None)[source]

Calculate the coefficient of variation.

Calculate the coefficient of variation of a variable given weights. The coefficient of variation is the square root of the variance of the incomes divided by the mean income. It has the advantages of being mathematically tractable and is subgroup decomposable, but is not bounded from above.

Parameters:
variablearray-like or str
weightsarray-like or str
Returns:
coefficient_variationfloat

References

Coefficient of variation. (2017, May 5). In Wikipedia, The Free Encyclopedia. Retrieved 15:03, May 15, 2017, from https://en.wikipedia.org/w/index.php?title=Coefficient_of_variation

ineqpy._statistics.kurt(variable=None, weights=None)[source]

Calculate the asymmetry coefficient.

Parameters:
variable1d-array
weights1d-array
Returns:
kurtfloat

Kurtosis coefficient.

Notes

It is an alias of the standardized fourth-order moment.

References

Moment (mathematics). (2017, May 6). In Wikipedia, The Free Encyclopedia. Retrieved 14:40, May 15, 2017, from https://en.wikipedia.org/w/index.php?title=Moment_(mathematics)

ineqpy._statistics.skew(variable=None, weights=None)[source]

Return the asymmetry coefficient of a sample.

Parameters:
variablearray-like, str
weightsarray-like, str
Returns:
skewfloat

Notes

It is an alias of the standardized third-order moment.

References

Moment (mathematics). (2017, May 6). In Wikipedia, The Free Encyclopedia. Retrieved 14:40, May 15, 2017, from https://en.wikipedia.org/w/index.php?title=Moment_(mathematics)

ineqpy._statistics.wvar(x, w, kind, out)[source]

Calculate weighted variance of X.

Calculates the weighted variance of x according to a kind of weights.

Parameters:
xnp.ndarray

Main variable.

wnp.ndarray

Weigths.

kindint

Has three modes to calculate de variance, you can control that with this argument, the values and the output are the next: * 1. population variance * 2. sample frequency variance * 3. sample reliability variance.

outnp.ndarray
Returns:
weighted_variancefloat

References

https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance #Weighted_incremental_algorithm

ineqpy._statistics.wcov(x, y, w, kind, out)[source]

Compute weighted covariance between x and y.

Compute the weighted covariance between two variables, we can chose which kind of covariance returns.

Parameters:
xnp.array

Main variable.

ynp.array

Second variable.

wnp.array

Weights.

kindint
Kind of weighted covariance is returned:

1 : population variance 2 : sample frequency variance 3 : sample reliability variance.

outnp.array
Returns:
weighted_covariance = float

References

https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online

ineqpy._statistics.online_kurtosis(x, w, out)[source]

Online kurtosis.

ineqpy._statistics.Mk(x, w, k, out)[source]

Calculate Mk.