Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Change over time

The question

You have a measure recorded over time — orders per day, revenue per month, the same customers before and after a change — and you want to know whether it is going up or down, how this period compares to the last one, or whether a change after some event is more than noise.

It sounds like:

  • “Is revenue going up?”
  • “How does this month compare to last month, and to the same month last year?”
  • “Did customers spend more after the launch than before it?”

There are three common shapes. Bucket the rows by period (day, week, month) and read the series, adding period-over-period changes or indexes. Test the whole series for a steady upward or downward trend. Or, when the same rows are measured twice, compare each row with itself before and after. The worked example below is that third shape, with no date field; for the period and trend shapes, pulse examples search time-series lists runnable examples, such as post_trend_on_dates (a trend test on weekly figures).

Pick your analysis

This question fits data shaped like:

  • time: one date field; measure: 1 or more numeric, categorical or bool fields

The operators that answer it, by kind; each name links to its catalog entry. Basic ones need the least setup; the worked example below uses AGG_AVERAGE and TEST_PAIRED_T.

Attributes

UseIn plain wordsLevel
ATTR_DATE_PARTAdds a calendar part of a date or datetime field to every row, such as the year, the month, a year-month like 202403 or the hour.basic

Filterers

UseIn plain wordsLevel
FILTER_DATE_RANGESKeeps only the rows whose date falls inside one of a set of named date ranges, such as custom fiscal quarters.basic

Groupers

UseIn plain wordsLevel
GROUP_DATESplits the rows by calendar period of a date, such as month, quarter, ISO week or weekday, to see a measure over time.basic
GROUP_DATE_RANGESLabels each row with the named date range its date falls in, such as custom fiscal quarters or before and after a launch.basic

Window operators

UseIn plain wordsLevel
WIN_DELTAAdds the change from a set number of rows earlier in the field’s own units, such as orders this month minus last month.basic
WIN_LAGAdds to every row the value of a field from a set number of rows earlier in the ordered series, such as last month’s sales.basic
WIN_LEADAdds to every row the value of a field from a set number of rows later in the ordered series, such as next month’s sales.basic
WIN_MOVING_AVGAdds a moving average: the mean of a field over a fixed number of neighbouring rows, smoothing short-term swings in a series.basic
WIN_PCT_CHANGEAdds the change from a set number of rows earlier as a fraction of the earlier value: 0.05 is a 5% rise on last month.basic
WIN_RUNNING_AVGAdds the average of a field over the rows so far in the ordered series, such as the average order value to date.basic
WIN_RUNNING_SUMAdds a running total of a field down the ordered rows, such as revenue for the year to date.basic
WIN_EWMAAdds a smoothed series: each new value counts for a fixed share w, the previous smoothed level for 1 - w, so older values fade.intermediate

Feature operators

UseIn plain wordsLevel
FEAT_DATE_FEATURESSplits a date into year, month, day, day of week and quarter fields, so each part can be filtered, grouped or modelled.basic

Statistical tests

UseIn plain wordsLevel
TEST_PAIRED_TChecks whether the average change between two measurements of the same rows, such as before and after, differs from zero.intermediate
TEST_TRENDChecks whether an ordered series, such as monthly totals, tends to keep rising or keep falling.intermediate
TEST_WILCOXON_SRRank-based check of whether paired before/after values tend to shift in one direction, without assuming a bell curve.intermediate
TEST_ANOVA_RMChecks whether the average differs across conditions when every subject is measured under each condition.advanced

Overlays

UseIn plain wordsLevel
OVERLAY_DELTA_VS_BASELINEEach point of an ordered series minus a chosen baseline point, in the value’s own units: how much it has moved since then.basic
OVERLAY_DELTA_VS_PRIOREach point of an ordered series minus the point before it, in the value’s own units: how much it changed from the previous period.basic
OVERLAY_INDEX_VS_BASELINEEach point of an ordered series as an index value against a chosen baseline point (point / baseline x 100), e.g. growth since launch.basic
OVERLAY_INDEX_VS_PRIOREach point of an ordered series as an index value against the point before it (point / prior x 100): period-on-period change.basic
OVERLAY_YOYEach period of a date-grouped series as an index value against the same period one year earlier (x 100): year-over-year change.basic
OVERLAY_INDEX_VS_ROLLING_MEANEach point of an ordered series as an index value against the rolling mean of the previous W points: is this period above its recent run?intermediate
OVERLAY_PROP_Z_VS_PRIORTwo-proportion z-test of each period’s share against the period before it: did awareness (or any yes/no share) change since last wave?intermediate
OVERLAY_ZSCORE_VS_ROLLINGHow many standard deviations each point sits from the rolling mean of the previous W points: a simple flag for unusual periods.intermediate
OVERLAY_T_VS_PRIORWelch t-test of each period against the period before it: did the average really change from the last wave, or is it noise?advanced
OVERLAY_Z_VS_PRIORLarge-sample z-test of each period’s mean against the period before it: did the average change from the last wave?advanced

A worked example

To run the example below yourself, write the example cohorts once and work from their directory, since command-line cohort paths resolve against the working directory (Get the data). Start in a scratch directory outside your PULSE_DATA_DIR, so pulse-data does not nest inside the directory pulse mcp serves:

pulse examples data --out pulse-data
cd pulse-data
pulse examples show paired_t_before_after > req.json
pulse api process --request req.json --json

Did customers spend more during the test period than they did before it?

The request (example paired_t_before_after; pulse examples show paired_t_before_after prints it):

{
  "aggregations": [
    {
      "type": "AGG_AVERAGE",
      "field": "revenue_before",
      "label": "avg_revenue_before"
    }
  ],
  "cohort": {
    "filename": "experiment.pulse"
  },
  "return": {
    "precision": 4
  },
  "tests": [
    {
      "type": "TEST_PAIRED_T",
      "field": "revenue",
      "field2": "revenue_before",
      "alpha": 0.05,
      "label": "revenue_lift_paired"
    }
  ]
}

The result:

{
  "data": [
    {
      "avg_revenue_before": 120.6
    }
  ],
  "metadata": {
    "total_rows": 400,
    "filtered_rows": 400,
    "cohort_file": "experiment.pulse"
  },
  "tests": [
    {
      "label": "revenue_lift_paired",
      "type": "TEST_PAIRED_T",
      "variant": "paired_two_sided",
      "statistic": 23.97,
      "df": 399,
      "p_value": 2.807e-79,
      "alpha": 0.05,
      "reject_null": true,
      "details": {
        "ci_high": 33.69,
        "ci_low": 28.58,
        "effect_size": {
          "cohens_d": 1.198
        },
        "mean_diff": 31.14,
        "n": 400,
        "variance": 675.2
      }
    }
  ],
  "components": {
    "aggregations": [
      {
        "label": "avg_revenue_before",
        "n": 400,
        "n_null": 0,
        "operator": {
          "sum": 4.824e+04
        }
      }
    ],
    "run": {
      "total_records": 400,
      "filtered_records": 400,
      "null_records": 0
    }
  },
  "returned": {
    "preset": "full",
    "digest": "rp1:2a47356146fe7626329ca77359f19495ac57bb6a599dfdd7658729be64597be6",
    "precision": 4
  }
}

Exponents print here as pulse api process --json prints them (6.069e+04); a tool that reformats JSON, such as jq, may print the same number as 6.069E+4.

Yes, clearly. Comparing each customer with themselves, revenue rose on average by roughly a quarter of the earlier level (the test’s mean_diff against avg_revenue_before, the average spend before, in the data row); the interval for that rise is narrow and well above zero, and the effect size is large. Pairing is what makes this sharp: each customer is their own baseline, so the wide differences between customers drop out. The test says spending rose, not why: the test period mixes the treatment with a gradual drift over time, so the rise belongs to both.

How to read the result

TEST_PAIRED_T

statistic

t is the average of the per-row differences (field - field2) measured in standard errors of that average. Values far from 0 in either direction are unlikely if the true average difference is zero.

Sign:

  • +: field is larger than field2 on average
  • -: field2 is larger than field on average

p_value

Follows the shared reading: see Reading a p-value.

details.mean_diff

The average of field - field2 over complete pairs, in the field’s own units.

Sign:

  • +: field is larger than field2 on average
  • -: field2 is larger than field on average

details.ci_low

Lower end of the confidence interval for the average difference (field - field2) at the 1 - alpha level (95% by default).

Caveats:

  • An interval that excludes 0 matches a p-value below alpha.

details.ci_high

Upper end of the confidence interval for the average difference (field - field2).

details.effect_size.cohens_d

d_z: the average difference divided by the standard deviation of the differences (not the d_av of the two fields’ own spreads).

Sign:

  • +: field is larger than field2 on average
  • -: field2 is larger than field on average

Caveats:

  • No sourced bands apply to d_z: Cohen’s 0.2 / 0.5 / 0.8 were set for gaps between independent groups. d_z = d / sqrt(2(1 - r)), so it reads larger than a between-group d when field and field2 correlate above 0.5 and smaller below it.
  • Do not compare d_z directly with a two-group d; report the mean difference alongside it.
  • When the standard deviation is zero, d is undefined and the key is left out rather than reported as 0.

More on reading it: TEST_PAIRED_T.

Pitfalls

  • Before and after is not cause and effect. Anything else that changed in the same window — season, prices, a gradual drift — lands in the difference too; a comparison group that did not get the change is what isolates it.
  • Periods of different length are not comparable. February has fewer days than March and a partial last month looks like a collapse; compare averages per day, or complete periods only.
  • Seasonality looks like a trend. A December peak is not growth; compare with the same period a year earlier, or remove the seasonal pattern first.
  • Thin periods swing wildly. With few rows per day, daily figures jump around and a trend test may miss a real drift; bucket into weeks or months, and read a short noisy series as inconclusive rather than flat.
  • Smoothing before testing overstates a trend. A moving average makes neighbouring points depend on each other, so a trend test on the smoothed series looks surer than the data allow; test the raw period figures.
  • Paired data need a paired test. The same customers before and after are not two independent groups; a paired test compares each customer with themselves and is far more sensitive.
  • Time zones move rows between days. A timestamp near midnight belongs to different days in different zones; set the zone the business reports in before bucketing.

Next steps

Related questions:

Skills: intents, aggregation-design, attribute-composition, feature-engineering, grouper-design, overlay-formula-namespace, overlay-pairwise, overlay-reference-tests, overlay-system, pairwise-n-sources, panel-n-sources, statistical-testing, test-variant-options, window-design, windows-first, op-agg-average, op-test-paired-t

From the command line:

  • pulse recommend --intent change_over_time --cohort PATH drafts requests for this question bound to your cohort’s fields.
  • pulse api predict checks a request against your cohort without running it.
  • pulse api process runs it.
  • pulse explain --response FILE --request REQ reads a result back in plain words: save the pulse api process --json output as FILE, and pass the request that produced it as REQ so the findings name its fields.