foryourhealth111-pixel/Vibe-Skills / bundled/skills/performing-causal-analysis
performing-causal-analysis
VerifiedEstimate causal effects from existing data. Use when fitting or interpreting DiD, ITS, synthetic control, regression discontinuity, or other treatment-effect analyses, including robustness checks and counterfactual plots. For choosing a study design before analysis, use designing-experiments instead.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.4 KB |
| reference/diff_in_diff.md | markdown | 1.7 KB |
| reference/interrupted_time_series.md | markdown | 1.5 KB |
| reference/synthetic_control.md | markdown | 1.4 KB |
reference/interrupted_time_series.md
View on GitHub# Causal Interrupted Time Series (ITS)
Interrupted Time Series (ITS) analyzes the effect of an intervention on a single time series by comparing the trend before and after the intervention.
## Class: `InterruptedTimeSeries`
```python
causalpy.experiments.InterruptedTimeSeries(
data,
treatment_time,
formula,
model=None,
**kwargs
)
```
### Parameters
* **`data`** (`pd.DataFrame`): Input dataframe. Index should ideally be a `pd.DatetimeIndex`.
* **`treatment_time`** (`Union[int, float, pd.Timestamp]`): The point in time when the intervention occurred.
* **`formula`** (`str`): Statistical formula (e.g., `"y ~ 1 + t + C(month)"`).
* **`model`**: A PyMC model (e.g., `cp.pymc_models.LinearRegression`) or a Scikit-Learn Regressor.
### How it Works
1. **Split**: Data is split into pre- and post-intervention.
2. **Fit**: Model is trained **only on pre-intervention data**.
3. **Predict**: Fitted model predicts the outcome for the post-intervention period.
4. **Impact**: Difference between observed post-intervention data and counterfactual predictions.
### Example
```python
import causalpy as cp
import causalpy.pymc_models as cp_pymc
import pandas as pd
df = cp.load_data("its")
df["date"] = pd.to_datetime(df["date"])
df.set_index("date", inplace=True)
treatment_time = pd.to_datetime("2017-01-01")
result = cp.InterruptedTimeSeries(
df,
treatment_time,
formula="y ~ 1 + t + C(month)",
model=cp_pymc.LinearRegression()
)
result.summary()
result.plot()
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |