Python scipy.stats.skewtest() Examples
The following are 13
code examples of scipy.stats.skewtest().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.stats
, or try the search function
.
Example #1
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_nd_input(self): x = np.array((-2,-1,0,1,2,3)*4)**2 x_2d = np.vstack([x] * 2).T for func in [mstats.normaltest, mstats.skewtest, mstats.kurtosistest]: res_1d = func(x) res_2d = func(x_2d) assert_allclose(res_2d[0], [res_1d[0]] * 2) assert_allclose(res_2d[1], [res_1d[1]] * 2)
Example #2
Source File: test_statstools.py From vnpy_crypto with MIT License | 5 votes |
def test_omni_normtest(): #tests against R fBasics from scipy import stats st_pv_R = np.array( [[3.994138321207883, -1.129304302161460, 1.648881473704978], [0.1357325110375005, 0.2587694866795507, 0.0991719192710234]]) nt = omni_normtest(x) assert_almost_equal(nt, st_pv_R[:, 0], 14) st = stats.skewtest(x) assert_almost_equal(st, st_pv_R[:, 1], 14) kt = stats.kurtosistest(x) assert_almost_equal(kt, st_pv_R[:, 2], 11) st_pv_R = np.array( [[34.523210399523926, 4.429509162503833, 3.860396220444025], [3.186985686465249e-08, 9.444780064482572e-06, 1.132033129378485e-04]]) x2 = x**2 #TODO: fix precision in these test with relative tolerance nt = omni_normtest(x2) assert_almost_equal(nt, st_pv_R[:, 0], 12) st = stats.skewtest(x2) assert_almost_equal(st, st_pv_R[:, 1], 12) kt = stats.kurtosistest(x2) assert_almost_equal(kt, st_pv_R[:, 2], 12)
Example #3
Source File: test_stats.py From Computable with MIT License | 5 votes |
def test_normalitytests(): # numbers verified with R: dagoTest in package fBasics st_normal, st_skew, st_kurt = (3.92371918, 1.98078826, -0.01403734) pv_normal, pv_skew, pv_kurt = (0.14059673, 0.04761502, 0.98880019) x = np.array((-2,-1,0,1,2,3)*4)**2 yield assert_array_almost_equal, stats.normaltest(x), (st_normal, pv_normal) yield assert_array_almost_equal, stats.skewtest(x), (st_skew, pv_skew) yield assert_array_almost_equal, stats.kurtosistest(x), (st_kurt, pv_kurt)
Example #4
Source File: test_stats.py From Computable with MIT License | 5 votes |
def test_skewtest_too_few_samples(): # Regression test for ticket #1492. # skewtest requires at least 8 samples; 7 should raise a ValueError. x = np.arange(7.0) assert_raises(ValueError, stats.skewtest, x)
Example #5
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_vs_nonmasked(self): x = np.array((-2,-1,0,1,2,3)*4)**2 assert_array_almost_equal(mstats.normaltest(x), stats.normaltest(x)) assert_array_almost_equal(mstats.skewtest(x), stats.skewtest(x)) assert_array_almost_equal(mstats.kurtosistest(x), stats.kurtosistest(x)) funcs = [stats.normaltest, stats.skewtest, stats.kurtosistest] mfuncs = [mstats.normaltest, mstats.skewtest, mstats.kurtosistest] x = [1, 2, 3, 4] for func, mfunc in zip(funcs, mfuncs): assert_raises(ValueError, func, x) assert_raises(ValueError, mfunc, x)
Example #6
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_axis_None(self): # Test axis=None (equal to axis=0 for 1-D input) x = np.array((-2,-1,0,1,2,3)*4)**2 assert_allclose(mstats.normaltest(x, axis=None), mstats.normaltest(x)) assert_allclose(mstats.skewtest(x, axis=None), mstats.skewtest(x)) assert_allclose(mstats.kurtosistest(x, axis=None), mstats.kurtosistest(x))
Example #7
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maskedarray_input(self): # Add some masked values, test result doesn't change x = np.array((-2,-1,0,1,2,3)*4)**2 xm = np.ma.array(np.r_[np.inf, x, 10], mask=np.r_[True, [False] * x.size, True]) assert_allclose(mstats.normaltest(xm), stats.normaltest(x)) assert_allclose(mstats.skewtest(xm), stats.skewtest(x)) assert_allclose(mstats.kurtosistest(xm), stats.kurtosistest(x))
Example #8
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_skewtest(self): # this test is for 1D data for n in self.get_n(): if n > 8: x, y, xm, ym = self.generate_xy_sample(n) r = stats.skewtest(x) rm = stats.mstats.skewtest(xm) assert_allclose(r[0], rm[0], rtol=1e-15) # TODO this test is not performed as it is a known issue that # mstats returns a slightly different p-value what is a bit # strange is that other tests like test_maskedarray_input don't # fail! #~ assert_almost_equal(r[1], rm[1])
Example #9
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_skewtest_2D_notmasked(self): # a normal ndarray is passed to the masked function x = np.random.random((20, 2)) * 20. r = stats.skewtest(x) rm = stats.mstats.skewtest(x) assert_allclose(np.asarray(r), np.asarray(rm))
Example #10
Source File: test_mstats_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_skewtest_2D_WithMask(self): nx = 2 for n in self.get_n(): if n > 8: x, y, xm, ym = self.generate_xy_sample2D(n, nx) r = stats.skewtest(x) rm = stats.mstats.skewtest(xm) assert_equal(r[0][0],rm[0][0]) assert_equal(r[0][1],rm[0][1])
Example #11
Source File: test_stats.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_skewtest_too_few_samples(): # Regression test for ticket #1492. # skewtest requires at least 8 samples; 7 should raise a ValueError. x = np.arange(7.0) assert_raises(ValueError, stats.skewtest, x)
Example #12
Source File: test_stats.py From GraphicDesignPatternByPython with MIT License | 4 votes |
def test_normalitytests(): assert_raises(ValueError, stats.skewtest, 4.) assert_raises(ValueError, stats.kurtosistest, 4.) assert_raises(ValueError, stats.normaltest, 4.) # numbers verified with R: dagoTest in package fBasics st_normal, st_skew, st_kurt = (3.92371918, 1.98078826, -0.01403734) pv_normal, pv_skew, pv_kurt = (0.14059673, 0.04761502, 0.98880019) x = np.array((-2,-1,0,1,2,3)*4)**2 attributes = ('statistic', 'pvalue') assert_array_almost_equal(stats.normaltest(x), (st_normal, pv_normal)) check_named_results(stats.normaltest(x), attributes) assert_array_almost_equal(stats.skewtest(x), (st_skew, pv_skew)) check_named_results(stats.skewtest(x), attributes) assert_array_almost_equal(stats.kurtosistest(x), (st_kurt, pv_kurt)) check_named_results(stats.kurtosistest(x), attributes) # Test axis=None (equal to axis=0 for 1-D input) assert_array_almost_equal(stats.normaltest(x, axis=None), (st_normal, pv_normal)) assert_array_almost_equal(stats.skewtest(x, axis=None), (st_skew, pv_skew)) assert_array_almost_equal(stats.kurtosistest(x, axis=None), (st_kurt, pv_kurt)) x = np.arange(10.) x[9] = np.nan with np.errstate(invalid="ignore"): assert_array_equal(stats.skewtest(x), (np.nan, np.nan)) expected = (1.0184643553962129, 0.30845733195153502) assert_array_almost_equal(stats.skewtest(x, nan_policy='omit'), expected) with np.errstate(all='ignore'): assert_raises(ValueError, stats.skewtest, x, nan_policy='raise') assert_raises(ValueError, stats.skewtest, x, nan_policy='foobar') x = np.arange(30.) x[29] = np.nan with np.errstate(all='ignore'): assert_array_equal(stats.kurtosistest(x), (np.nan, np.nan)) expected = (-2.2683547379505273, 0.023307594135872967) assert_array_almost_equal(stats.kurtosistest(x, nan_policy='omit'), expected) assert_raises(ValueError, stats.kurtosistest, x, nan_policy='raise') assert_raises(ValueError, stats.kurtosistest, x, nan_policy='foobar') with np.errstate(all='ignore'): assert_array_equal(stats.normaltest(x), (np.nan, np.nan)) expected = (6.2260409514287449, 0.04446644248650191) assert_array_almost_equal(stats.normaltest(x, nan_policy='omit'), expected) assert_raises(ValueError, stats.normaltest, x, nan_policy='raise') assert_raises(ValueError, stats.normaltest, x, nan_policy='foobar')
Example #13
Source File: ABuStatsUtil.py From abu with GNU General Public License v3.0 | 4 votes |
def normality_stats(arr): """ 统计信息偏度,峰度,正态分布检测,p-value eg: input: 2014-07-25 223.57 2014-07-28 224.82 2014-07-29 225.01 ... 2016-07-22 222.27 2016-07-25 230.01 2016-07-26 225.93 output: array skew = -0.282635248604699 array skew p-value = 0.009884539532576725 array kurt = 0.009313464006726946 array kurt p-value = 0.8403947352953821 array norm = NormaltestResult(statistic=6.6961445106692237, pvalue=0.035152053009441256) array norm p-value = 0.035152053009441256 input: tsla bidu noah sfun goog vips aapl 2014-07-25 223.57 226.50 15.32 12.110 589.02 21.349 97.67 2014-07-28 224.82 225.80 16.13 12.450 590.60 21.548 99.02 2014-07-29 225.01 220.00 16.75 12.220 585.61 21.190 98.38 ... ... ... ... ... ... ... ... 2016-07-22 222.27 160.88 25.50 4.850 742.74 13.510 98.66 2016-07-25 230.01 160.25 25.57 4.790 739.77 13.390 97.34 2016-07-26 225.93 163.09 24.75 4.945 740.92 13.655 97.76 output: array skew = [-0.2826 -0.2544 0.1456 1.0322 0.2095 0.095 0.1719] array skew p-value = [ 0.0099 0.0198 0.1779 0. 0.0539 0.3781 0.1124] array kurt = [ 0.0093 -0.8414 -0.4205 0.4802 -1.547 -0.9203 -1.2104] array kurt p-value = [ 0.8404 0. 0.0201 0.0461 1. 0. 0. ] array norm = NormaltestResult(statistic=array([ 6.6961, 52.85 , 7.2163, 69.0119, 3.7161, 69.3468, 347.229 ]), pvalue=array([ 0.0352, 0. , 0.0271, 0. , 0.156 , 0. , 0. ])) array norm p-value = [ 0.0352 0. 0.0271 0. 0.156 0. 0. ] :param arr: pd.DataFrame or pd.Series or Iterable """ log_func = logging.info if ABuEnv.g_is_ipython else print log_func('array skew = {}'.format(scs.skew(arr))) log_func('array skew p-value = {}'.format(scs.skewtest(arr)[1])) log_func('array kurt = {}'.format(scs.kurtosis(arr))) log_func('array kurt p-value = {}'.format(scs.kurtosistest(arr)[1])) log_func('array norm = {}'.format(scs.normaltest(arr))) log_func('array norm p-value = {}'.format(scs.normaltest(arr)[1]))