Skip to content

TRACES v2.0.0: traces_ts package, v1 bug fixes, autocorrelation-aware statistics, uv/CI - #1

Merged
SwiftyProjects merged 8 commits into
mainfrom
release/v2.0.0
Sep 15, 2026
Merged

SwiftyProjects merged 8 commits into
mainfrom
release/v2.0.0

Conversation

@SwiftyProjects

Copy link
Copy Markdown
Owner

Summary

Two years after v1.0.0, a full modernization of TRACES ahead of a v2.0.0 release: the analysis moves from notebook cells into a tested traces_ts package, several v1 calculation bugs are fixed, and the default significance tests now account for autocorrelation. Results differ from v1; AnalysisConfig.classic() / traces analyze --classic give v1-style statistics.

What changed

Environment

  • pyproject.toml + uv.lock; works with uv sync or pip install -e . in any venv (verified by installing the built wheel in a plain pip venv)
  • environment.yml is conda-forge only and just installs the package
  • Python 3.11-3.14; tested on NumPy 2.5, pandas 3.0, SciPy 1.18, matplotlib 3.11
  • Distribution traces-ts, import traces_ts (traces is already taken on PyPI)

v1 bugs fixed

  • CCF optimal lag ignored max_lag (v1 reported lags of 11-12 with max_lag=10)
  • CCF and time-delayed correlations used opposite lag signs; now positive lag = series_1 leads
  • CCF was not normalized (values were r x (n-1), e.g. 50.9); CCF(0) now equals Pearson r
  • Hard-coded Time column; first column is now the time column as documented
  • No missing-value handling despite docs; explicit raise / drop / interpolate
  • (count, method) legend labels in the method-performance plot

Statistics (on by default)

  • Autocorrelation-adjusted p-values via effective sample size (Pyper & Peterman, 1998)
  • Benjamini-Hochberg FDR correction across pairs
  • Double AR pre-whitening + residual-based Bonferroni band for lead/lag detection (order-independent)
  • New none relationship type; documented evidence_score replaces the old confidence score

Features

  • traces analyze CLI: CSV, Excel (results/summary/config sheets), Markdown report, figures
  • CSV input, configurable time column, date parsing, detrending (none / linear / difference)
  • New per-pair CCF and rolling-correlation plots; relationship matrix covers all series
  • Notebook rewritten as a thin six-step walkthrough with a classic-vs-v2 comparison

Quality

  • 58 pytest tests, including statistical calibration checks
  • GitHub Actions: ruff, tests on Linux (3.11-3.14), Windows and macOS, lowest supported dependency versions, notebook execution, CLI smoke test, build
  • README, guides and formulae rewritten; CHANGELOG with migration table; CITATION.cff
  • Example outputs are generated from real runs by scripts/generate_examples.py (the old hand-written step*.txt outputs did not match the code)

Why the statistics changed

Simulated independent series, n = 52, alpha = 0.05 (1,000 pairs each):

Series type naive p v2 p naive lag detection v2 lag detection
White noise 6.3% 5.6% 1.7% 1.4%
AR(1), phi = 0.95 55.7% 6.2% 43.2% 1.5%
Random walk 66.8% 14.4% 33.2% 1.5%
Smoothed noise 51.4% 6.0% 49.8% 7.6%

A true 3-step lead is detected 84-93% of the time with the correct sign 98% of the time.

Sample dataset A1 (relationship-type counts):

Type classic (v1-style) v2 default
linear 4 4
lagged 7 0
complex 33 5
none 1 36

Reviewer notes

  • Breaking change: result columns are snake_case (series_1, relationship_type, evidence_score, ccf_peak_lag, ...); see the migration table in CHANGELOG.md
  • Random walks and strong deterministic trends still inflate adjusted p-values (~14-15%); reports flag high-persistence series and recommend detrend="difference". Documented under Limitations in docs/Formulae.md
  • The CI workflow has not run on GitHub before this PR; watch the first run
  • After merge: tag v2.0.0 and publish a GitHub release from the CHANGELOG

Test plan

  • uv run pytest (58 passed)
  • uv run pytest --nbmake notebooks
  • uv run ruff check . and uv run ruff format --check .
  • Lowest direct dependencies on Python 3.11 (58 passed)
  • uv build, wheel installed in a plain pip venv, traces analyze on dataset B1
  • GitHub Actions CI green

🤖 Generated with Claude Code

SwiftyProjects and others added 8 commits September 15, 2026 12:46
…ironment

- PEP 621 metadata (distribution traces-ts, import traces_ts; 'traces' is taken on PyPI)
- Works with uv sync or pip install -e . in any venv; environment.yml now just installs the package
- Drop the Anaconda 'defaults' channel, add ruff/pytest/nbmake dev group

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Fixes v1 defects:
- CCF optimal lag is now restricted to +/-max_lag (v1 reported lags of 11-12 with max_lag=10)
- One lag sign convention everywhere: positive lag means series_1 leads series_2
- CCF is normalized so CCF(0) equals Pearson r (v1 values were r * (n-1))
- Time column defaults to the first column instead of a hard-coded 'Time'
- Explicit missing-value policy (raise/drop/interpolate) instead of silent NaN results
- Method-performance legend no longer shows '(count, method)' artifacts

Statistical safeguards (on by default, AnalysisConfig.classic() turns them off):
- Autocorrelation-adjusted p-values via effective sample size (Pyper & Peterman 1998)
- Benjamini-Hochberg FDR correction across pairs
- AR pre-whitening before lag detection, Bonferroni band across searched lags
- 'none' relationship type and min_correlation gate; evidence score documented

Adds CSV input, detrending options, CSV/Excel/Markdown export, figure export and a
'traces analyze' command-line interface.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Single (Box-Jenkins) pre-whitening filtered both series with series_1's AR model,
so detection depended on pair order and flagged spurious lags on the smooth sample
data. Each series is now filtered with its own AR model and the CCF band uses the
effective sample size of the residuals. Simulated false-positive rate: 0.5-7.6%,
power for a true 3-step lead: 84-93%.

Relationship matrix now shows 'none' pairs in grey, trims the empty row/column and
labels lags relative to the row series.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…of traces_ts

Configuration, loading, correlations, lead/lag, classification and export now call
the package instead of redefining the pipeline in each cell. Adds a v1-style
(classic) vs v2 comparison and removes the duplicated README/guide cells.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Tests Python 3.11-3.14 on Linux plus Windows and macOS, and the lowest supported
dependency versions (seaborn floor raised to 0.13.2 for pandas 2.2 compatibility).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ITATION.cff

- Formulae now cover effective sample size, FDR, pre-whitening, bands, classification and
  evidence score, with references and limitations
- Operational and Component Flexibility guides describe the notebook, CLI and Python API
- Example outputs are regenerated from real runs by scripts/generate_examples.py,
  replacing hand-written step outputs that did not match the code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SwiftyProjects
SwiftyProjects merged commit 1e80ab2 into main Sep 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant