Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

quantile chokes on integral vectors if it has to interpolate #1333

Closed
HarlanH opened this Issue · 11 comments

4 participants

Harlan Harris Stefan Karpinski Mike Nolta John Myles White
Harlan Harris
julia> quantile([1,2,3,4.], .5)
2.5

julia> quantile([1,2,3,4], .5)
InexactError()
 in assign at array.jl:493
 in quantile at statistics.jl:361
 in quantile at statistics.jl:368

Anyone want to argue the correct behavior? Return a float? Round to the nearest integer? Fail with a nicer error message?

Stefan Karpinski

Oo. This is a bit of a tough call. If it rounds to a float then you'd want the answer to always be a float, which is kind of a bummer.

Harlan Harris
Mike Nolta
Collaborator

Since we've implemented quantile variant #7, i think by definition we have to return 2.5.

Harlan Harris
Mike Nolta
Collaborator

The problem is that "variant 7" as described by R doesn't apply in a
language like Julia that doesn't convert most numbers to floats.

What? Sure it does. It's just math.

... or write quantile(Float)->Float and quantile(Int)->Int with different behavior.

That's just too weird and magical.

If we want quantile to return the same type as the input, we should switch to variant 1 (like Mathematica) or variant 3.

Harlan Harris
Mike Nolta
Collaborator

To me, it'd be more than a little weird for the median of a set of integers to be a float.

Wait, what?

julia> median([1,2,3,4])
2.5
Harlan Harris
John Myles White
Collaborator
Harlan Harris
John Myles White
Collaborator
Mike Nolta nolta closed this in 0a3b7a3
Jeffrey Sarnoff JeffreySarnoff referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Jeffrey Sarnoff JeffreySarnoff referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.