Package: pyhomogeneity
pyHomogeneityWhat is the Homogeneity Test ?The homogeneity test is a statistical test method, that checks if two (or more) datasets come from the same distribution or not. In a time series, the homogeneity test is applied to detect one (or more) change/breakpoint in the series.  This breakpoint occurs where the data set changes its distribution. Lots of statistical analyses require a homogenous dataset. That's why it is an important test in statistical analysis.pyHomogeneityis a pure Python implementation for the homogeneity test. There are several tests available to check the homogeneity of a time series. pyHomogeneity package can perform six commonly used Homogeneity test listed below:Pettitt test (pettitt_test)Standard Normal Homogeinity Test (SNHT) Test (snht_test)Buishand Q Test (buishand_q_test)Buishand's Range Test (buishand_range_test):Buishand's Likelihood Ration Test (buishand_likelihood_ratio_test)Buishand U Test (buishand_u_test)Function details:All Homogeneity test functions have almost similar input parameters. These are:x:   a vector (list, numpy array or pandas series) dataalpha: significance level (0.05 default)sim: No. of monte carlo simulation for p-value calculation.And all Homogeneity tests return a named tuple which contained:h: True (if data is nonhomogeneous) or False (if data is homogeneous)cp: probable change point locationp: p value of the significance testU/T/Q/R/V: test statistics which depends on the test methodavg: mean values at before and after the change pointDependenciesFor the installation ofpyHomogeneity, the following packages are required:numpyscipyInstallationYou can installpyHomogeneityusing pip. For Linux userssudopipinstallpyhomogeneityor, for Windows userpipinstallpyhomogeneityOr you can clone the repo and install it:gitclonehttps://github.com/mmhs013/pyhomogeneitycdpyhomogeneity
pythonsetup.pyinstallTestspyHomogeneityis automatically tested usingpytestpackage on each commithere, but the tests can be manually run:pytest -vUsageA quick example ofpyHomogeneityusage is given below. Several more examples are providedhere.importnumpyasnpimportpyhomogeneityashg# Data generation for analysisdata=np.random.rand(360,1)result=hg.pettitt_test(data)print(result)Output are like this:Pettitt_Test(h=False,cp=89,p=0.1428,U=3811.0,avg=mean(mu1=0.5487521427805625,mu2=0.46884198890609463))Whereas, the output is a named tuple, so user can call by name for specific result:print(result.cp)print(result.avg.mu1)or, user can directly unpack results like this:h,cp,p,U,mu=hg.pettitt_test(x,0.05)ContributionspyHomogeneityis a community project and welcomes contributions. Additional information can be found in thecontribution guidelinesCode of ConductpyHomogeneitywishes to maintain a positive community. Additional details can be found in theCode of ConductReferencesAlexandersson, H., 1986. A homogeneity test applied to precipitation data. Journal of climatology, 6(6), pp.661-675. doi:10.1002/joc.3370060607Buishand, T.A., 1982. Some methods for testing the homogeneity of rainfall records. Journal of hydrology, 58(1-2), pp.11-27. doi:10.1016/0022-1694(82)90066-XPettitt, A.N., 1979. A non-parametric approach to the change-point problem. Journal of the Royal Statistical Society: Series C (Applied Statistics), 28(2), pp.126-135. doi:10.2307/2346729Pohlert, T., 2016. Package 'trend'. Title Non-Parametric Trend Tests and Change-Point Detection.Verstraeten, G., Poesen, J., Demaree, G. and Salles, C., 2006. Long-term (105 years) variability in rain erosivity as derived from 10-min rainfall depth data for Ukkel (Brussels, Belgium): Implications for assessing soil erosion rates. Journal of Geophysical Research: Atmospheres, 111(D22). doi:10.1029/2006JD007169