Correlate two metrics
correlate_metricsCompare two metrics over a date range, calculating Pearson's r and Spearman's rho across day lags to find lead-lag relationships.
Instructions
Correlate two metrics over a range, sweeping a range of day-offsets.
Joins the two metrics by UTC calendar date rather than by cycle, and reports Pearson's r and Spearman's rho at every lag from -lag_days to +lag_days (inclusive), each with its own sample size. A positive lag means metric_a's date precedes metric_b's by that many days -- metric_a "leads". A lag whose surviving pairs fall below 8 is reported as refused rather than omitted.
Correlation here is descriptive, not causal: WHOOP daily samples are autocorrelated (today's recovery is not independent of yesterday's), so do not read a strong r at some lag as proof that one metric drives the other, and do not treat a handful of weeks as a stable finding.
Args: metric_a: First metric name, as in metric_trend. metric_b: Second metric name. start: ISO 8601 start of the range. end: ISO 8601 end of the range. lag_days: Sweep radius in days (default 3, capped at 14); the sweep covers every integer lag from -lag_days to +lag_days.
Raises: ValueError: if lag_days is negative.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | Yes | ||
| start | Yes | ||
| lag_days | No | ||
| metric_a | Yes | ||
| metric_b | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||