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

Distribution shape

The question

You have one numeric measure — income, order value, a duration, a test score — and you want to know its shape before you summarise or test it: is it roughly a bell curve, lopsided with a long tail, flat or peaked, and are there values far out from the rest?

It sounds like:

  • “Is income skewed?”
  • “Does this score follow a normal distribution, so a t-test is safe?”
  • “Is the spend of the top customers far out from everyone else?”

Start with the figures that describe shape: the spread (standard deviation, range, percentiles), the skewness (lopsidedness) and the kurtosis (how heavy the tails are). Add a histogram-style grouping to see it, and a normality test only when a later step assumes a bell shape. To compare one group’s shape with another’s, use a two-sample Kolmogorov-Smirnov test.

Pick your analysis

This question fits data shaped like:

  • measure: 1 or more numeric 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, AGG_KURTOSIS, AGG_SKEWNESS and AGG_STDDEV.

Aggregators

UseIn plain wordsLevel
AGG_MEDIANMiddle value of a numeric field once sorted: the typical row, not pulled by a few extreme values.basic
AGG_PERCENTILEValue of a numeric field below which a chosen share of rows fall, such as the 90th percentile of delivery time.basic
AGG_RANGEDistance between the smallest and largest value of a numeric field, over all rows or per group.basic
AGG_STDDEVTypical distance of a numeric field’s values from their average, in the field’s own units, over all rows or per group.basic
AGG_SKEWNESSHow lopsided a numeric field is: positive when a long tail runs to high values, negative when it runs to low ones.intermediate
AGG_VARIANCESpread of a numeric field as the average squared distance from its mean, in squared units, over all rows or per group.intermediate
AGG_VEC_SDStandard deviation of each item of a battery or mix, as one list per group: how much the group’s rows disagree on each item.intermediate
AGG_KURTOSISHow heavy a numeric field’s tails are next to a normal distribution: positive when extreme values are more common.advanced

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

Groupers

UseIn plain wordsLevel
GROUP_RANGESplits a number into bands of equal width, such as ages 20-30 and 30-40, to see how values spread or to compare bands.basic
GROUP_ROUNDEDGroups a number by rounding it down to a multiple of a step, such as 23 and 27 both to 20, naming each group by that multiple.basic
GROUP_QUANTILESplits the rows into equal-sized groups by rank of a number, such as quartiles or deciles of spend, to compare top and bottom.intermediate

Feature operators

UseIn plain wordsLevel
FEAT_LOGAdds a field holding the natural log of 1 + the value, which pulls in a long tail of large values so a skewed field is easier to model.intermediate
FEAT_SQRTAdds a field holding the square root of the value, a gentler squeeze than a log for counts with a moderate long tail.intermediate

Statistical tests

UseIn plain wordsLevel
TEST_KSChecks whether a numeric field’s values follow the same distribution in two groups, comparing their whole shape.intermediate
TEST_SHAPIRO_WILKChecks whether a numeric field looks normally distributed, overall or within each group.intermediate
TEST_BROWN_FORSYTHEChecks whether the spread of a numeric field differs across groups: a robust test of equal variances.advanced
TEST_MARDIAChecks whether a set of numeric fields looks jointly normal, through their combined skew and tail weight.advanced

Overlays

UseIn plain wordsLevel
OVERLAY_KS_VS_POPKolmogorov-Smirnov test on a numeric facet: checks whether a subset’s distribution departs from a comparison population’s.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 shape_moments > req.json
pulse api process --request req.json --json

Is customer income skewed, or does it follow a bell curve?

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

{
  "aggregations": [
    {
      "type": "AGG_AVERAGE",
      "field": "income",
      "label": "mean_income"
    },
    {
      "type": "AGG_STDDEV",
      "field": "income",
      "label": "stddev_income"
    },
    {
      "type": "AGG_SKEWNESS",
      "field": "income",
      "label": "skew_income"
    },
    {
      "type": "AGG_KURTOSIS",
      "field": "income",
      "label": "kurt_income"
    }
  ],
  "cohort": {
    "filename": "customers.pulse"
  },
  "return": {
    "preset": "standard",
    "precision": 4
  }
}

The result:

{
  "data": [
    {
      "kurt_income": 2.991,
      "mean_income": 4.378e+04,
      "skew_income": 1.603,
      "stddev_income": 2.721e+04
    }
  ],
  "metadata": {
    "total_rows": 200,
    "filtered_rows": 200,
    "cohort_file": "customers.pulse"
  },
  "returned": {
    "preset": "standard",
    "digest": "rp1:3740c6cf7d1b2603620bc368cb97f40488ddae2bc40c4df12447e16826612255",
    "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.

It is clearly skewed to the right. Skewness is well above zero, which means a long tail of high earners pulls the average up, and the excess kurtosis is well above zero too, so extreme incomes turn up far more often than a bell curve would predict. The standard deviation is about three fifths of the mean, another sign of a wide, lopsided spread. For a measure shaped like this, report the median beside the mean, and consider a log transform before a test that assumes a bell shape. On a sample of this size a single extreme income can move skewness and kurtosis a lot, so read percentiles or a histogram beside them.

How to read the result

AGG_KURTOSIS

value

How heavy the tails are next to a normal distribution. Pulse computes the population EXCESS kurtosis g2: the average fourth-power z-score minus 3, (m4/n) / (m2/n)^2 - 3, where the components m2 and m4 are SUMS of squared and fourth-power distances from the mean (not yet divided by n), so a normal distribution scores 0. It can never fall below -2.

Sign:

  • +: heavier tails than a normal distribution: extreme values turn up more often than the spread suggests
  • -: lighter tails than a normal distribution: values far from the mean turn up less often than the spread suggests, as in a flat (uniform) or two-humped spread; it does not mean the values are bounded

Caveats:

  • There are no sourced bands for kurtosis: the cut-offs quoted for it (such as 2 or 7) are pass/fail normality screens from particular fields, disagree on whether 3 has been subtracted, and are not graded readings.
  • Small-n bias: g2 differs from the adjusted G2 that Excel KURT and SPSS print, and on small groups the gap is large; neither is stable on a handful of rows.
  • It reads null when no row has a value, when n is 1 or when the variance is zero (every value the same): no shape can be seen there. A 0 is a real, balanced reading; on a tiny group check components n before trusting it.
  • It measures the tails, not how pointed the peak looks, and a single extreme value can dominate it.

More on reading it: AGG_KURTOSIS.

AGG_SKEWNESS

value

How lopsided the values are around their mean. Pulse computes the population moment coefficient g1: the average cubed z-score, (m3/n) / (m2/n)^1.5, where the components m2 and m3 are SUMS of squared and cubed distances from the mean (not yet divided by n). 0 means the values balance around the mean.

Sign:

  • +: a longer or heavier tail to the right: a few values sit far above the rest
  • -: a longer or heavier tail to the left: a few values sit far below the rest

Caveats:

  • The sign does not fix whether the mean sits above or below the median: the two often disagree on whole-number or many-peaked fields, so read AGG_MEDIAN beside AGG_AVERAGE for that.
  • There are no sourced bands for skewness: the 0.5 / 1 rules of thumb in circulation trace to secondary quotations that could not be checked against their source, so compare values with each other rather than with a fixed cut-off.
  • Small-n bias: g1 runs smaller in size than the adjusted G1 that Excel SKEW, SPSS and SAS print (G1 = g1 * sqrt(n(n-1)) / (n-2)), so the two disagree on small groups and converge as n grows; on a handful of rows neither is stable.
  • It reads null when no row has a value, when n is 1 or when the variance is zero (every value the same): no shape can be seen there. A 0 is a real, balanced reading; on a tiny group check components n before trusting it.
  • Deviations are cubed, so one extreme value can set the sign and size on its own.

More on reading it: AGG_SKEWNESS.

AGG_STDDEV

value

The typical distance of a value from the group’s mean, in the field’s own units. 0 means every value is the same; for a roughly bell-shaped field about two thirds of the values sit within one standard deviation of the mean.

Caveats:

  • It is the spread of the rows, not the precision of the mean: for how precisely the average is known, read AGG_CI_LOWER / AGG_CI_UPPER.
  • By default Pulse divides by n (the population form); most tools report the sample form, dividing by n - 1, which is slightly larger. The gap matters only on small groups; params.ddof 1 gives the sample form.
  • Each distance is squared before averaging, so a few extreme values inflate it; for a skewed field a percentile range describes the spread better.
  • A group with a single value reads 0: no spread can be seen in one value, which is not the same as a group whose values agree. With params.ddof 1 it reads null instead (weighted: when the weights sum to 1 or less).

More on reading it: AGG_STDDEV.

Pitfalls

  • Skewness and kurtosis move with a few rows. One extreme value can change both a lot, especially on a small sample; look at the percentiles or a histogram before you rest a decision on them.
  • A normality test answers a narrow question. On a large sample it flags departures from a bell curve too small to matter; on a small one it misses large ones. Ask whether the departure is big enough to affect the test you plan to run.
  • Most real measures are not bell-shaped. Money, durations and counts usually have a long upper tail; that is a feature of the data, not an error. Report the median beside the mean, or work on a log scale.
  • An outlier is a lead, not a mistake. A value far from the rest may be a recording error or your most important customer; check it before you trim or cap it.
  • Kurtosis here is excess kurtosis. A bell curve scores zero, not three; a positive figure means heavier tails than a bell curve, a negative one lighter.
  • Shape depends on the population you filtered. Mixing two groups with different typical values can produce two humps or a false skew; check the shape within each group as well.

Next steps

Related questions:

Skills: intents, aggregation-design, attribute-composition, facet-design, 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, op-agg-average, op-agg-kurtosis, op-agg-skewness, op-agg-stddev

From the command line:

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