Skip to main content

A Python implementation of the Chow Test for structural breaks.

Project description

PyChow: A Python Implementation of the Chow Test

Overview

The Chow Test is used to determine if there is a structural break in a regression model, often applied in time series or panel data. This implementation provides a simple, reusable interface for performing the test using Python.


Formula

The Chow Test statistic is calculated as follows:

[ F = \frac{(RSS_{combined} - (RSS_1 + RSS_2)) / k}{(RSS_1 + RSS_2) / (N_1 + N_2 - 2k)} ]

Where:

  • ( RSS_{combined} ): Residual sum of squares for the combined regression model.
  • ( RSS_1, RSS_2 ): Residual sum of squares for the two separate regressions.
  • ( k ): Number of parameters (including intercept) in the regression model.
  • ( N_1, N_2 ): Number of observations in each subset.

The ( F )-statistic follows the ( F )-distribution with degrees of freedom:

  • Numerator: ( k )
  • Denominator: ( N_1 + N_2 - 2k )

Installation

To install PyChow:

pip install pychow

Usage

Example Code

import pandas as pd
import numpy as np
from pychow import ChowTest

# Example dataset
data = pd.DataFrame({
    'x': np.arange(1, 21),
    'y': np.concatenate([np.arange(1, 11), np.arange(21, 31)])
})

# Perform Chow Test
breakpoint = 10
result = ChowTest.chow_test(data, breakpoint, dependent_var='y', independent_vars=['x'])
print(result)

Output

The result will be a dictionary with the Chow Test statistic and the p-value:

{
    "Chow Test Statistic": 180.0,
    "P-value": 0.0
}

Parameters

  • data: A Pandas DataFrame containing your dataset.
  • breakpoint: The index at which the dataset is split into two parts.
  • dependent_var: Name of the dependent variable (target column).
  • independent_vars: List of names for independent variables (features).

Features

  • Easy-to-use interface.
  • Works with any dataset in Pandas DataFrame format.
  • Outputs a dictionary with the test statistic and p-value.

Contributing

Feel free to fork the repository, submit pull requests, or open issues for feature requests and bugs.


License

MIT License

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

pychow-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pychow-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pychow-0.1.0.tar.gz.

File metadata

  • Download URL: pychow-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for pychow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 38cec145f17b370c2324eceb74e374d6e6fd7c9b441412af12f81ea09de06e7e
MD5 c8d62f1eab65ff2cd1b0401b25d9cd32
BLAKE2b-256 c4b9272cdbee3b3f554f38ef6ae9a416d7fd0c774918bc31c92dd71b3eda3a10

See more details on using hashes here.

File details

Details for the file pychow-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pychow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for pychow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0548fddbe05036352b1454fddb1ea98dba4bd9d9b4323389d995d529c78031
MD5 bb4dfd1ce6603292f5a4b280dfc476e6
BLAKE2b-256 2dfb2eaae797a4f308e1e4710adb93da6b1af37ca46e9c6653de3281e0d81b9d

See more details on using hashes here.

Supported by

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