In [54]:
import statistics
import scipy.stats as stats
import pandas as pd
import numpy as np
import ineqpy
In [42]:
x = np.random.randn(10)
In [43]:
w = abs(np.random.randn(10))
w = w / w.sum()
In [44]:
np.mean(x)
Out[44]:
In [45]:
ineqpy.mean(variable=x)
Out[45]:
In [46]:
np.var(x)
Out[46]:
In [47]:
ineqpy.var(variable=x)
Out[47]:
In [48]:
stats.skew(x)
Out[48]:
In [49]:
ineqpy.skew(variable=x)
Out[49]:
In [52]:
stats.kurtosis(x) + 3
Out[52]:
In [51]:
ineqpy.kurt(variable=x)
Out[51]:
In [4]:
x = np.array([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,6,6,6,6,7,7,7,8,8,9])
In [5]:
xi, fi = np.unique(x, return_counts=True)
In [6]:
xi # values
Out[6]:
In [7]:
fi # absolute frequency
Out[7]:
In [18]:
data = pd.DataFrame(np.c_[x, np.ones(len(x))], columns=list('xf'))
In [19]:
data
Out[19]:
In [20]:
data_weighted = pd.DataFrame(np.c_[xi,fi], columns=list('xf'))
In [21]:
data_weighted
Out[21]:
In [22]:
np.mean(x)
Out[22]:
In [23]:
data.mean()
Out[23]:
In [24]:
ineqpy.mean(variable=x)
Out[24]:
In [25]:
ineqpy.mean(data, 'x')
Out[25]:
In [26]:
ineqpy.mean(variable=xi, weights=fi)
Out[26]:
In [27]:
ineqpy.mean(data, 'x', 'f')
Out[27]:
In [28]:
np.var(x, ddof=1) # numpy (ddof=1)
Out[28]:
In [29]:
stats.variation(x) # scipy (ddof=0)
Out[29]:
In [30]:
data.var() # pandas (ddof=1)
Out[30]:
In [31]:
ineqpy.var(variable=x)
Out[31]:
In [32]:
ineqpy.var(variable=xi, weights=fi)
Out[32]:
In [33]:
stats.skew(x)
Out[33]:
In [41]:
data.skew()
Out[41]:
In [34]:
ineqpy.skew(variable=x)
Out[34]:
In [35]:
ineqpy.skew(variable=xi, weights=fi)
Out[35]:
In [36]:
stats.kurtosis(x) + 3
Out[36]:
In [40]:
data.kurt()+3
Out[40]:
In [37]:
ineqpy.kurt(variable=x)
Out[37]:
In [38]:
ineqpy.kurt(variable=xi, weights=fi)
Out[38]:
In [ ]: