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

Weighted quantiles? #47

Open
mbostock opened this issue Jan 24, 2017 · 4 comments
Open

Weighted quantiles? #47

mbostock opened this issue Jan 24, 2017 · 4 comments
Assignees

Comments

@mbostock
Copy link
Member

I tend to do something like this, but it’s pretty inefficient and requires integer weights:

var values = d3.merge(samples.map(s => d3.range(weight(s)).map(() => value(s))));

A related question is how to expose weighted quantiles as a scale.

@Fil
Copy link
Member

Fil commented Jun 24, 2020

Implemented in https://observablehq.com/d/f7139ebca0286081

it's a bit less performant than d3.quantile since I used sort instead of quickselect. (It might be possible to use quickselect iteratively. [EDIT:] it's probably too difficult, I'm giving up on this aspect.)

@Fil
Copy link
Member

Fil commented Jun 24, 2020

Also, not sure about the API. The typical use case might be with data=[{value, weight},…] so we would need two accessors. But then, when we have an array of weights (as in the notebook), it would be a clunky accessor (_,i) => weights[i].

@Fil Fil self-assigned this Jun 24, 2020
@Fil
Copy link
Member

Fil commented Jun 25, 2020

I added a note about the interpolation method—I'm using R-2, not R-7. My thinking here is that the (possibly non-integer) weights do not correspond to repeated point samples that have by chance yielded the same value, but rather represent contiguous classes (or blocks) of a certain width.

image

We want to interpolate the value only when we are exactly on the edge between two blocks.

@Fil
Copy link
Member

Fil commented Jun 25, 2020

The API now allows for an optional accessor (last argument of the function), weights can be specified as an accessor or an iterable, and values as an iterable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants