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

name: op-agg-percentile
description: Configurable percentile of the field; requires sorting the full value set.
kind: operator
category: AGG
operator: AGG_PERCENTILE
type: reference
applies_to: process, compose, predict
examples_tags: [distribution-shape, buffered-pipeline]

Use when

Value of a numeric field below which a chosen share of rows fall, such as the 90th percentile of delivery time.

Questions it answers:

  • How long do the slowest 10% of deliveries take in each region?
  • What income marks the top quarter of respondents?

Use something else:

  • AGG_MEDIAN when you want the 50th percentile.
  • ATTR_PERCENTILE when you want each row’s own percentile position.

Params

NameTypeDefaultDescription
percentilefloat(required)Percent [0, 100] (95 = p95), not a 0–1 fraction.
orderedboolfalseCategorical field: dictionary order is the level order.
levelsarray—Level order, lowest first, by label; implies ordered.

Ordered: R quantile(type = 1) over level ranks — the lowest level whose cumulative share reaches p/100 (0 → lowest seen); weighted, Σw ≥ p·Σw/100. method type1.

Weighted: Hmisc wtd.quantile — sort by value; h = p·(Σw−1); x(k) = first value with cumulative Σw ≥ k+1 (snapped to an integer within 1e-9); interpolate x(⌊h⌋)..x(⌈h⌉). probability weights first rescaled to Σw = n (rows used) — scale-invariant; frequency weights stay raw = type 7 on duplicated rows.

Inputs

field — admitted types: see ## Contract.

Output

Scalar float64. Per-group when wired under a grouper. Ordered: the level’s dictionary index — a code.

Reading the output

  • value: The value below which the requested share of the group’s values fall, in the field’s own units: at percentile 90 about 90% of values sit at or below it. Pulse interpolates linearly between the two nearest sorted values (R’s default, type 7), so it may be a value no row holds.
    • Caveat: Tools use different interpolation rules, so on small groups another tool can return a somewhat different value for the same percentile.
    • Caveat: A percentile near 0 or 100 on a small group rests on one or two rows and moves a lot when they change.

Components

  • p — Requested percentile
  • position — Index in sorted set (weighted: ⌊h⌋, expanded)
  • lower — Lower bracket value
  • upper — Upper bracket value
  • method — Interpolation method (e.g. "linear")
  • value — Resolved percentile
  • n_unlisted — ordered only: rows whose label levels omits

Contract

  • Types (field): date, datetime, f32, f64, packed_bool, u16, u32, u4, u64, u8; any other scalar type is PULSE_FIELD_TYPE_UNSUPPORTED; decimal128 is PULSE_AGG_NOT_MEANINGFUL_FOR_DECIMAL.
  • Weight: weighted under frequency and probability weights.
  • Streaming: buffered only; components none. Use AGG_AVERAGE or accept the buffered path; exact percentiles need sorted input.
  • Components: n, n_null, p, position, lower, upper, method, value; optional sum_weights, n_eff, n_weight_invalid, n_unlisted.

Gotchas

  • Buffered: cohort-sized memory peak.
  • Absent, null or out-of-range percentile refused.
  • No non-null value → null (NaN), never 0.
  • Ordered: unlisted labels dropped; overlays refuse the code (categorical_code); PROCESSING_CONFIG reason ordered_needs_categorical / unknown_level / duplicate_level.

See