-
Notifications
You must be signed in to change notification settings - Fork 187
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
medianIndex/quantileIndex doesn’t handle missing data #275
Comments
It also seems to returning the last index if there are multiple elements with the median value? {
const sorted = d3.sort(penguins, (d) => d.body_mass_g);
const i = d3.medianIndex(sorted, (d) => d.body_mass_g);
return sorted[i - 5].body_mass_g; // 4050
} |
Ah ha. The problem is that we’re dropping undefined values in the initial filter: Line 36 in c62f825
This means that the indexes are indexes into the filtered array, and hence are wrong. If we pre-filter the data the correct result is returned: {
const filtered = penguins.filter((d) => d.body_mass_g);
const i = d3.medianIndex(filtered, (d) => d.body_mass_g);
return filtered[i];
} Although, we are still returning the last index of equivalent values (it appears), and I think it would be preferable to return the first. But, any of those would be correct as long as we document it. |
ouch!
|
d3.medianIndex returns one less than the index of the median element. For example:
I don’t think this is the intended behavior, even if we were trying to chose the “lower” element in the case where the array length is even. I expect it to return the index of the median value instead.
Previously #140 #159.
The text was updated successfully, but these errors were encountered: