Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 95th and 99th percentile to aggregation #3577

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/docs/transforms/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ All valid aggregate operations.
| median | The median field value.|
| q1 | The lower quartile boundary of field values.|
| q3 | The upper quartile boundary of field values.|
| p95 | The 95th percentile of field values.|
| p99 | The 99th percentile of field values.|
| ci0 | The lower boundary of the bootstrapped 95% confidence interval of the mean field value.|
| ci1 | The upper boundary of the bootstrapped 95% confidence interval of the mean field value.|
| min | The minimum field value.|
Expand Down
2 changes: 1 addition & 1 deletion packages/vega-statistics/src/quartiles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import quantiles from './quantiles';

export default function(array, f) {
return quantiles(array, [0.25, 0.50, 0.75], f);
return quantiles(array, [0.25, 0.50, 0.75, 0.95, 0.99], f);
}
8 changes: 8 additions & 0 deletions packages/vega-transforms/src/util/AggregateOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export const AggregateOps = {
value: m => m.cell.data.q3(m.get),
req: ['values'], idx: 3
},
p95: {
value: m => m.cell.data.p95(m.get),
req: ['values'], idx: 3
},
p99: {
value: m => m.cell.data.p99(m.get),
req: ['values'], idx: 3
},
min: {
init: m => m.min = undefined,
value: m => m.min = (Number.isNaN(m.min) ? m.cell.data.min(m.get) : m.min),
Expand Down
8 changes: 8 additions & 0 deletions packages/vega-transforms/src/util/TupleStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ prototype.q3 = function(get) {
return this.quartile(get)[2];
};

prototype.p95 = function(get) {
return this.quartile(get)[3];
};

prototype.p99 = function(get) {
return this.quartile(get)[4];
};

prototype.ci = function(get) {
if (this._get !== get || !this._ci) {
this._ci = bootstrapCI(this.values(), 1000, 0.05, get);
Expand Down
2 changes: 2 additions & 0 deletions packages/vega-typings/types/runtime/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export type AggregateOps =
| 'median'
| 'q1'
| 'q3'
| 'p95'
| 'p99'
| 'min'
| 'max'
| 'argmin'
Expand Down
2 changes: 1 addition & 1 deletion packages/vega/test/specs-valid/window.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "aggregate", "value": "sum",
"bind": {
"input": "select",
"options": ["sum", "count", "average", "median", "stdev"]
"options": ["sum", "count", "average", "median", "stdev", "p95", "p99"]
}
},
{
Expand Down