Skip to main content

A python package for homogeneity test.

Project description

pyHomogeneity

Build Status PyPI PyPI - License PyPI - Status Downloads PyPI - Python Version DOI

What 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.

pyHomogeneity is 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:

  1. Pettitt test (pettitt_test)

  2. Standard Normal Homogeinity Test (SNHT) Test (snht_test)

  3. Buishand Q Test (buishand_q_test)

  4. Buishand's Range Test (buishand_range_test):

  5. Buishand's Likelihood Ration Test (buishand_likelihood_ratio_test)

  6. 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) data
  • alpha: 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 location
  • p: p value of the significance test
  • U/T/Q/R/V: test statistics which depends on the test method
  • avg: mean values at before and after the change point

Dependencies

For the installation of pyHomogeneity, the following packages are required:

Installation

You can install pyHomogeneity using pip. For Linux users

sudo pip install pyhomogeneity

or, for Windows user

pip install pyhomogeneity

Or you can clone the repo and install it:

git clone https://github.com/mmhs013/pyhomogeneity
cd pyhomogeneity
python setup.py install

Tests

pyHomogeneity is automatically tested using pytest package on each commit here, but the tests can be manually run:

pytest -v

Usage

A quick example of pyHomogeneity usage is given below. Several more examples are provided here.

import numpy as np
import pyhomogeneity as hg

# Data generation for analysis
data = 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)

Contributions

pyHomogeneity is a community project and welcomes contributions. Additional information can be found in the contribution guidelines

Code of Conduct

pyHomogeneity wishes to maintain a positive community. Additional details can be found in the Code of Conduct

References

  1. Alexandersson, H., 1986. A homogeneity test applied to precipitation data. Journal of climatology, 6(6), pp.661-675. doi:10.1002/joc.3370060607

  2. Buishand, 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-X

  3. Pettitt, 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/2346729

  4. Pohlert, T., 2016. Package 'trend'. Title Non-Parametric Trend Tests and Change-Point Detection.

  5. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhomogeneity-1.1.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

pyhomogeneity-1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pyhomogeneity-1.1.tar.gz.

File metadata

  • Download URL: pyhomogeneity-1.1.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for pyhomogeneity-1.1.tar.gz
Algorithm Hash digest
SHA256 55bc59bcc591e7dd9fa04d081c8cd50be74106f349378d7bc97c2ebfd5fb65a1
MD5 08e8f15e1946e554ffcbdb10bcf6549e
BLAKE2b-256 7df55e16ae2b77a76733747bad0e7eef611d1556169ebdf301d9134e897d3540

See more details on using hashes here.

File details

Details for the file pyhomogeneity-1.1-py3-none-any.whl.

File metadata

  • Download URL: pyhomogeneity-1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for pyhomogeneity-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 837ebcae1f08f7094567265f9b14b27bda2c0857ffb5a65a0a3a2ee701856da2
MD5 dced4d133ce9b04e35f4b307a3db86ae
BLAKE2b-256 e28aa1ffa82674cc748bdf8d46c3d1f681651679038f1cbd9bb0fae7b649d457

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page