ineqpy.grouped.stats
Stats’ module.
Module Contents
Functions
|
Calculate variance. |
|
Calculate the asymmetry of each h stratum. |
|
Calculate quasivariance. |
- ineqpy.grouped.stats.variance_hat_group(data=None, variable='x', weights='w', group='h')[source]
Calculate variance.
Data a DataFrame calculates the sample variance for each stratum. The objective of this function is to make it easy to calculate the moments of the distribution that follows an estimator, eg. Can be used to calculate the variance that follows the mean.
- Parameters:
- datapandas.DataFrame
Dataframe containing the series needed for the calculation
- xstr
- weightsstr
Name of the weights w in the DataFrame
- groupstr
Name of the stratum variable h in the DataFrame
- Returns:
- vhat_hpandas.Series
A series with the values of the variance of each h stratum.
Examples
>>> # Computes the variance of the mean >>> data = pd.DataFrame(data=[renta, peso, estrato], columns=["renta", "peso", "estrato"]) >>> v = variance_hat_group(data) >>> v stratum 1 700.917.728,64 2 9.431.897.980,96 3 317.865.839.789,10 4 741.304.873.092,88 5 535.275.436.859,10 6 225.573.783.240,68 7 142.048.272.010,63 8 40.136.989.131,06 9 18.501.808.022,56 dtype: float64
>>> # the value of de variance of the mean: >>> v_total = v.sum() / peso.sum() ** 2 24662655225.947945
- ineqpy.grouped.stats.moment_group(data=None, variable='x', weights='w', group='h', order=2)[source]
Calculate the asymmetry of each h stratum.
- Parameters:
- variablearray or str
- weightsarray or str
- grouparray or str
- datapd.DataFrame, optional
- orderint, optional
- Returns:
- moment_of_orderfloat
- ineqpy.grouped.stats.quasivariance_hat_group(data=None, variable=None, weights=None, group=None)[source]
Calculate quasivariance.
Sample variance of variable, calculated as the second-order central moment.
- Parameters:
- datapd.DataFrame, optional
pd.DataFrame that contains all variables needed.
- variablearray or str
variable x apply the statistic. If data is None then must pass this argument as array, else as string name in data
- weightsarray or str
weights can be interpreted as frequency, probability, density function of x, each element in x. If data is None then must pass this argument as array, else as string name in data
- grouparray or str
group is a categorical variable to calculate the statistical by each group. If data is None then must pass this argument as array, else as string name in data
- Returns:
- shat2_grouparray or pd.Series
Notes
This function is useful to calculate the variance of the mean.
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)&oldid=778996402