Metadata-Version: 2.4
Name: bcad
Version: 1.0.0
Summary: Bootstrap Comparison of Attractor Dimensions
Home-page: https://github.com/yairdaon/BCAD
Author: Kris V. Parag, Amit Huppert, Uri Obolski
Author-email: Yair Daon <yair.daon@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/yairdaon/BCAD
Project-URL: Repository, https://github.com/yairdaon/BCAD
Project-URL: Paper, https://doi.org/10.1111/2041-210X.70066
Keywords: time-series analysis,causal inference,dynamical systems,dimension estimation,bootstrap
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: matplotlib
Requires-Dist: scikit-learn
Requires-Dist: scikit-dimension
Requires-Dist: optht
Requires-Dist: joblib
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

Code and data for running "bootstrap comparison of attractor dimension" (BCAD). BCAD is a method for *refuting* the existence of causal relations between two observables of a (noisy dynamical) system.

See the paper: [Refuting causal relations for synchronized pathogen dynamics](https://doi.org/10.1111/2041-210X.70066).

## Installation

```bash
pip install bcad
```

## Command line usage

```bash
bcad    # Runs BCAD on all bundled US state data
```

## Python usage example

```python
import pandas as pd
from bcad.helpers import load_state, infer, decisions
from bcad.rypdal_sugihara import transform
from bcad.ssa import denoise

# Load bundled data for a single state
df = load_state("New_York")
df = (df - df.mean()) / df.std()

# Parameters
M = int(365 * 3 / 7)  # SSA window: 3 years, weekly data
tau = 12               # time delay for embedding
window = 12            # window for reproduction number
shift = -1             # time shift for R calculation
n_bootstrap = 200      # number of bootstrap resamples

# Denoise with Singular Spectrum Analysis
dd = denoise(df, M=M)

# Compute reproduction number from pneumonia/influenza incidence
dd = dd.assign(R=transform(dd.pi_inc, window=window, shift=shift)).dropna()

# Run BCAD
res = infer(dd, n_bootstrap=n_bootstrap, tau=tau, predictors=['R', 'AH'])
aggd = decisions(res)

# BCAD refutes a causal relation X -> Y when dim(X) > dim(Y) significantly
aggd = aggd[['pval', 'theta_hat', 0.95, 0.99]].assign(refute=aggd[0.95] < 0)
print(aggd)
```
