Skip to content

Conversation

@JeanVanDyk
Copy link

@JeanVanDyk JeanVanDyk commented Nov 24, 2025

Here is a first draft. I still need to add these enhancements :

5.1 Persistence Analysis Methods

  • Method: analyze_persistence()
  • Returns: Dictionary with mean effects, persistence ratio, total effects
  • Status: Deferred (can be added later)

5.2 Decay Model Fitting

  • Method: fit_decay_model(decay_type='exponential')
  • Purpose: Fit parametric models to post-intervention impacts
  • Status: Deferred (can be added later)

5.3 Comparison Period Summary

  • Enhancement: Implement period='comparison' in effect_summary()
  • Purpose: Comparative summary with persistence metrics showing:
    • Post-intervention effect as percentage of intervention effect
    • Posterior probability that some effect persisted
    • Comparison of HDI intervals between periods
  • Status: Currently raises NotImplementedError (can be implemented in Phase 2 or deferred to Phase 5)

5.4 Enhanced Plotting

  • Enhancement: Update plot() methods to visually distinguish three periods
  • Features:
    • Different colors/styles for intervention vs post-intervention
    • Vertical line at treatment_end_time
    • Separate impact panels or annotations
  • Status: Deferred (current plotting works but could be enhanced)

📚 Documentation preview 📚: https://causalpy--575.org.readthedocs.build/en/575/

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 97.96954% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.60%. Comparing base (c1cd88f) to head (73ea19c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
causalpy/experiments/interrupted_time_series.py 93.47% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #575      +/-   ##
==========================================
+ Coverage   91.95%   92.60%   +0.64%     
==========================================
  Files          33       34       +1     
  Lines        4776     5354     +578     
==========================================
+ Hits         4392     4958     +566     
- Misses        384      396      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JeanVanDyk
Copy link
Author

Hi @drbenvincent ,

I think I've tackled all the requirements you mentionned in the issue. Please let me know your thoughts on this !

I've however did not implemented the fit_decay_model at that point. If you think it's needed, could you give me more details about it ? I didn't fully understand what were you expecting.

@@ -0,0 +1,442 @@
{
Copy link
Collaborator

@drbenvincent drbenvincent Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Concise. Rather than saying it extends, could you change the language so it's a bit more...

For the fixed-period intervention cases (like a marketing promotion, or public policy intervention), we can make our interrupted time series experiment aware of this by providing kwargs...

And can we change the notebook title to "Interrupted Time Series with post-intervention analysis"


Reply via ReviewNB

@@ -0,0 +1,442 @@
{
Copy link
Collaborator

@drbenvincent drbenvincent Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Concise. Can you maybe add that persistence could in reality caused by brand awareness effects.

And can you slightly decrease the effect size. I think it is good to make it obvious that there's an effect, so it's clear in the results plots what is happening. Though the current effect size seems pretty massive.


Reply via ReviewNB

@@ -0,0 +1,442 @@
{
Copy link
Collaborator

@drbenvincent drbenvincent Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get the visualisation immediately after the parameter estimation. That way the visual intuition of the results will be clear and readers can interpret the numerical results summaries with that context already loaded in their brain


Reply via ReviewNB

@drbenvincent drbenvincent linked an issue Nov 24, 2025 that may be closed by this pull request
Copy link
Collaborator

@drbenvincent drbenvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can you update the existing demo notebook its_lift_test. That one has a time-limited intervention period, so is ideal for showing the new functionality. So basically just add in the extra kwarg. Should get updated plot no problem. Just need to add in the calls to the additional effect summary methods.
  • Please add the new notebook to /docs/source/notebooks/index.md so that it appears in the rendered docs
  • Don't worry about fit_decay_model. That's an entirely optional utility method which presumably would only be useful in specific situations, depending on what the effect decay looked like.

"metadata": {},
"source": [
"Run the analysis\n",
"\n",
Copy link
Collaborator

@drbenvincent drbenvincent Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. But can you move this new note up into the intro for this notebook. Could also mention that specific examples are shown in other notebooks, but this one focuses on a point intervention - rather than a fixed-period intervention.


Reply via ReviewNB

@JeanVanDyk
Copy link
Author

Hi @drbenvincent ! I've updated everything, please let me know if you need other changes.

Copy link
Collaborator

@drbenvincent drbenvincent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data : pd.DataFrame
A pandas dataframe with time series data. The index should be either
a DatetimeIndex or numeric (integer/float).
treatment_time : Union[int, float, pd.Timestamp]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be painfully explicit about treatment_time and treatment_end_time being inclusive of the dates given? That is $>=$, not $>$. If that is indeed the case.

self.model.calculate_cumulative_impact(self.post_intervention_impact)
)

def effect_summary(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InterruptedTimeSeries class is the only experiment class in the repository that overrides effect_summary (lines 491-664). All other experiment classes (SyntheticControl, DifferenceInDifferences, RegressionDiscontinuity, etc.) rely on the base class implementation in base.py, which auto-detects experiment type and dispatches to centralized helper functions in reporting.py. The override introduces ~170 lines of duplicated logic for computing statistics, generating tables, and generating prose that already exists in the base class and reporting module. This creates a maintenance burden where future changes to effect summary logic need to be updated in multiple places. An alternative approach would be to either: (1) add the period parameter to the base class effect_summary with ITS-specific handling, or (2) create a separate ITS-specific method like effect_summary_by_period() to make it clear this is a specialized feature. However, this concern need not be a blocker for merging—the functionality itself is solid and well-tested. We could create a follow-up issue to refactor this to align with repository patterns after the feature is merged.

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.

Enhancement: Three-Period Interrupted Time Series Design

2 participants