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

Benchmark against a reference

The question

You have a figure — an average, a share, a total, a score — and something to hold it against: a target you set, the whole population, another group, last wave or a reference request. You want to know whether your figure sits above or below that reference, by how much, and whether the gap is bigger than the noise in the rows you have.

It sounds like:

  • “Is our average order value above the target we set?”
  • “Which regions sit above the total on revenue?”
  • “How does this wave’s mix compare with the last one?”

Decide first what the reference is, because it picks the analysis. A fixed figure you supply takes a one-sample test (a t-test for an average). The total or the population takes an index or a z-score overlay: an index of one hundred means level with the reference, and a z-score says how many standard errors the figure sits above or below it. Another group, another wave or another request takes a delta (the plain difference) or an index overlay against that group, wave or request.

Pick your analysis

This question fits data shaped like:

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

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, AGG_COUNT and TEST_T.

Aggregators

UseIn plain wordsLevel
AGG_AUCHow well a score separates a yes/no outcome: the chance that a randomly picked yes row scores higher than a randomly picked no row.intermediate
AGG_MAEAverage size of a prediction’s miss in the actual’s own units, comparing an actual field with a prediction field row by row.intermediate
AGG_MAPEAverage size of a prediction’s miss as a share of the actual value, comparing an actual field with a prediction field row by row.intermediate
AGG_RMSETypical size of a prediction’s miss in the actual’s own units, with large misses counting more: the root of the average squared miss.intermediate

Attributes

UseIn plain wordsLevel
ATTR_PERCENTILEAdds to every row its percentile rank, rank / n * 100: the share of rows at or below it when values are untied.basic
ATTR_PROFILE_SIMILARITYAdds to every row how closely its related fields match a target profile: an ideal pattern, a benchmark, or its own segment target.intermediate
ATTR_TSCOREAdds to every row its T-score: the z-score rescaled so the mean is 50 and one standard deviation is 10.intermediate
ATTR_VEC_DISTANCEAdds to every row how far its set of related fields lies from a target profile, optionally in units of each field’s spread.intermediate
ATTR_ZSCOREAdds to every row its z-score: how many standard deviations the row’s value sits above or below the mean.intermediate
ATTR_REG_FITTEDAdds to every row the value a straight-line model predicts for its target from its predictors.advanced
ATTR_REG_PREDICTAdds to every row the value a model fitted once, elsewhere in the request, predicts for it from the row’s own predictor values.advanced
ATTR_REG_RESIDUALAdds to every row its residual: the actual target value minus the value a straight-line model predicts for it.advanced

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_DENSE_RANKRanks rows within each partition in the chosen order; rows with equal values share a rank and the next follows on: 1, 2, 2, 3.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_RANKRanks rows within each partition in the chosen order; rows with equal values share a rank and the next skips: 1, 2, 2, 4.basic
WIN_SHAREAdds each row’s share of its partition’s total, or the running share down the ordered rows, such as the share of defaults caught so far.basic
WIN_FORMULAAdds a number to every result row computed from that row’s columns and earlier windows, such as one share divided by another.intermediate
WIN_LIFTAdds how many times its share of one column a row holds of another, such as a decile’s share of defaults over its share of loans.intermediate

Statistical tests

UseIn plain wordsLevel
TEST_TChecks whether a numeric field’s average differs from a target value, or between two groups (Welch’s version).intermediate
TEST_HOTELLING_T2Checks whether several numeric fields, taken together as one profile, differ from a target, between two groups, or before vs after.advanced

Overlays

UseIn plain wordsLevel
OVERLAY_DELTA_VS_MARGINEach crosstab cell minus its row, column or grand margin, in the cell’s own units: how far a cell sits above or below its margin.basic
OVERLAY_DELTA_VS_SIBLINGEach group’s value minus one named group’s value, in the value’s own units: how far every group sits from, say, the control group.basic
OVERLAY_INDEX_VS_MARGINIndex value of each crosstab cell against its row, column or grand margin (cell / margin x 100): which cells over- or under-index?basic
OVERLAY_INDEX_VS_POPEach category’s (or histogram bin’s) share in a facet subset as an index value against its share in a comparison population (x 100).basic
OVERLAY_INDEX_VS_SIBLINGEach group’s value as an index value against one named group (group / sibling x 100), such as every store against the flagship.basic
OVERLAY_CHISQ_VS_POPChi-square goodness-of-fit test on a facet: checks whether a subset’s category mix departs from a comparison population’s mix.intermediate
OVERLAY_DELTA_VS_REFEach cell or group of a target Compose request minus the same coordinate in the reference request, in the target’s own units.intermediate
OVERLAY_DELTA_VS_STAGEA process-chain stage’s result minus an earlier stage’s result at the same coordinate, in the later stage’s own units.intermediate
OVERLAY_INDEX_VS_REFIndex value of each cell or group of a target Compose request against the same spot in the reference request (target / reference x 100).intermediate
OVERLAY_INDEX_VS_STAGEIndex value of a process-chain stage’s result against an earlier stage’s result at the same coordinate (target / reference x 100).intermediate
OVERLAY_PANEL_INDEX_VS_REFIndex values of several target Compose requests against one shared reference request, one layer per target (target / reference x 100).intermediate
OVERLAY_ZSCORE_VS_MARGINEach crosstab cell’s gap from its row, column or grand margin, in standard deviations of the cells in that slice: which cells stand out?intermediate
OVERLAY_ZSCORE_VS_POPPuts each category’s share gap with a comparison population on a z-score scale; for numeric bins it says nothing about the subset.intermediate
OVERLAY_ZSCORE_VS_TOTALHow many standard deviations each group’s value sits from the average of all groups on a grouped result: which groups stand out?intermediate
OVERLAY_KS_VS_POPKolmogorov-Smirnov test on a numeric facet: checks whether a subset’s distribution departs from a comparison population’s.advanced
OVERLAY_RAKERake a crosstab to known row and column totals: the fitted table, per-cell adjustment factors and whether the fit converged.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 t_test_one_sample > req.json
pulse api process --request req.json --json

Do customers spend more on average than the target of 100 per customer?

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

{
  "aggregations": [
    {
      "type": "AGG_AVERAGE",
      "field": "revenue",
      "label": "avg_revenue"
    },
    {
      "type": "AGG_COUNT",
      "field": "revenue",
      "label": "n"
    }
  ],
  "cohort": {
    "filename": "experiment.pulse"
  },
  "return": {
    "precision": 4
  },
  "tests": [
    {
      "type": "TEST_T",
      "field": "revenue",
      "alpha": 0.05,
      "label": "revenue_vs_100",
      "params": {
        "mu": 100.0
      }
    }
  ]
}

The result:

{
  "data": [
    {
      "avg_revenue": 151.7,
      "n": 400
    }
  ],
  "metadata": {
    "total_rows": 400,
    "filtered_rows": 400,
    "cohort_file": "experiment.pulse"
  },
  "tests": [
    {
      "label": "revenue_vs_100",
      "type": "TEST_T",
      "variant": "one_sample",
      "statistic": 12.2,
      "df": 399,
      "p_value": 2.495e-29,
      "alpha": 0.05,
      "reject_null": true,
      "details": {
        "ci_high": 160.1,
        "ci_low": 143.4,
        "effect_size": {
          "cohens_d": 0.6102
        },
        "mean": 151.7,
        "mu": 100,
        "n": 400,
        "variance": 7186
      }
    }
  ],
  "components": {
    "aggregations": [
      {
        "label": "avg_revenue",
        "n": 400,
        "n_null": 0,
        "operator": {
          "sum": 6.069e+04
        }
      },
      {
        "label": "n",
        "n": 400,
        "n_null": 0
      }
    ],
    "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, comfortably. The average customer brought in about half as much again as the target, and the test says an average this far above the target would almost never turn up if the true average sat at the target: the p-value is tiny and the whole confidence interval lies above it. Cohen’s d puts the gap at a medium size next to how much customers vary, so plenty of individual customers can still sit below the target even though the average clears it. The test compares one average with a fixed figure you supply, so choose the target before looking at the data; to benchmark against another group instead, use a two-sample test.

How to read the result

TEST_T

statistic

t is the gap between averages measured in standard errors: the sample mean minus the target value (one-sample), or the first group’s mean minus the second’s (two-sample, Welch). Values far from 0 in either direction are unlikely if the true gap is zero.

Sign:

  • +: the sample mean is above the target, or the first group in details.groups has the higher mean
  • -: the sample mean is below the target, or the second group in details.groups has the higher mean

Caveats:

  • The two-sample form is Welch’s by default: degrees of freedom (df) are adjusted for unequal variances and are usually not a whole number. Under params.variance pooled it is Student’s t on n_a + n_b - 2 df, with the pooled variance in details.pooled_variance.

p_value

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

details.reference

Present only with params.reference: the split_by level read second in details.groups, so diff, its interval, the statistic and the signed effect size read the other group minus this one.

details.diff

Two-sample only: the first group’s mean minus the second’s, in the field’s own units.

Sign:

  • +: the first group in details.groups is higher (alphabetical order; with params.reference, the non-reference group)
  • -: the second group in details.groups is higher (alphabetical order; with params.reference, the reference)

details.ci_low

Lower end of the confidence interval at the 1 - alpha level (95% by default): for the mean itself in the one-sample form, for the difference in means (details.diff) in the two-sample form.

Caveats:

  • In the one-sample form the interval is around the mean, not around mean minus target: compare it with the target value directly.

details.ci_high

Upper end of the same confidence interval: for the mean (one-sample) or for the difference in means (two-sample).

details.effect_size.cohens_d

The gap in standard-deviation units: (mean - target) / SD for one sample, (first mean - second mean) / pooled SD for two groups. 0.5 means the averages sit half a standard deviation apart.

Bands (convention: Cohen (1988); a labelled convention, not a rule):

Absolute valueLabel
below 0.2very small
from 0.2 to below 0.5small
from 0.5 to below 0.8medium
0.8 and abovelarge

Sign:

  • +: the mean is above the target, or the first group in details.groups is higher
  • -: the mean is below the target, or the second group in details.groups is higher

Caveats:

  • This d divides by the pooled standard deviation of the two groups, even though the test itself does not assume equal variances; when spreads differ a lot, d describes neither group exactly.
  • When the standard deviation is zero, d is undefined and the key is left out rather than reported as 0.

details.diff_unadjusted

Present only with params.covariate: the raw first-minus-second difference of means on the same rows; details.diff, its interval, the statistic, p, mean, variance and cohens_d are the covariate-adjusted figures.

Sign:

  • +: the first group in details.groups is higher (alphabetical order; with params.reference, the non-reference group)
  • -: the second group in details.groups is higher (alphabetical order; with params.reference, the reference)

Caveats:

  • Cohen’s d here divides by the adjusted spread, so it is larger than the raw d: compare it only with other adjusted d’s.

details.theta

Present only with params.covariate: the slope of the outcome on the covariate pooled over both groups; each row is read as outcome - theta x (covariate - covariate_mean).

Caveats:

  • Null when the covariate is constant: nothing is adjusted then. It is estimated from the same data, which standard CUPED practice ignores in the interval.

details.covariate_mean

Present only with params.covariate: the covariate’s mean over both groups, the point the adjustment centres on.

details.variance_reduction

Present only with params.covariate: the share of the difference’s sampling variance the covariate removed (0.6 = the interval is about 37% narrower than unadjusted).

Caveats:

  • Null when theta is; below 0 means the covariate made the estimate noisier, so drop it. Use a covariate measured before assignment: one the treatment moved biases diff.

details.n_covariate_dropped

Present only with params.covariate: rows with an outcome and a group but a null covariate, left out of the test (n counts the rest).

More on reading it: TEST_T.

Pitfalls

  • Choose the reference before you look. A target picked after seeing the data, or the one comparison that happened to look good, makes any gap look convincing; write the reference down first.
  • An index is a ratio, not a test. An index of one hundred and twenty says the figure is a fifth above the reference; it says nothing about whether that gap could come from the rows you happened to collect. Read the base counts, or use a test or a z-score overlay to judge it.
  • A group is part of its own total. When a large group is compared with a total it makes up much of, the gap shrinks towards zero; for a fair contrast compare it with everyone else, or with a sibling group.
  • Sums and averages index differently. Indexing each group’s total against the grand total gives its share of the whole, which grows with group size; index an average or a rate when you want to compare how the typical row performs.
  • A small p-value is not a big gap. With many rows a gap too small to matter still clears the bar; read the size of the gap and the effect size beside the p-value.
  • Many groups against one reference inflate false alarms. Scoring every region or every cell against the total makes some stand out by luck; use the request’s multiplicity block to adjust the p-values.
  • Survey data may need a weight. An unweighted figure describes the sample; set the request’s weight when you benchmark against a population figure.

Next steps

Related questions:

Skills: intents, aggregation-design, attribute-composition, facet-design, overlay-formula-namespace, overlay-pairwise, overlay-reference-tests, overlay-system, pairwise-n-sources, panel-n-sources, process-chain, statistical-testing, test-variant-options, window-design, windows-first, op-agg-average, op-agg-count, op-test-t

From the command line:

  • pulse recommend --intent benchmark --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.