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

Allow function as first argument of median #141

Open
KronosTheLate opened this issue Feb 27, 2023 · 5 comments
Open

Allow function as first argument of median #141

KronosTheLate opened this issue Feb 27, 2023 · 5 comments

Comments

@KronosTheLate
Copy link
Contributor

See this asymmerty:

julia> using Statistics

julia> v = randn(10);

julia> mean(abs, v)
0.6470633745357454

julia> median(abs, v)
ERROR: MethodError: no method matching median(::typeof(abs), ::Vector{Float64})
Closest candidates are:
  median(::Any) at ~/.julia/juliaup/julia-1.8.5+0.x64.linux.gnu/share/julia/stdlib/v1.8/Statistics/src/Statistics.jl:855
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

Is there any reason for it? If not, a method for median should be added that takes a function as the first argument.

@josemanuel22
Copy link
Contributor

josemanuel22 commented Apr 24, 2023

I understand that if this functionality is being considered to be added, we should also consider extending the quantile function analogously. Isn't that so? @KronosTheLate

@KronosTheLate
Copy link
Contributor Author

I have only used the quantile function a handfull of times, and I have never had this need.

Also, I am not sure if the quantile can be conceptually lumped in with summary statistics like mean and median. It does not clearly feel so for me, as the quantile is not one number, but a function a parameter from 0 to 1.

So I am rather agnostic, and think that a case needs to be made as for why quantile should have such a method.

@josemanuel22
Copy link
Contributor

We will have to think about it, in the meantime, you could use something like:

v = randn(10)
median(mappedarray(abs, v)) = 0.3167044909082123

@KronosTheLate
Copy link
Contributor Author

It is not hard to make you own version, it is just that mean and median are so similar in nature that it like a weird API for them to have different methods.

But sure, thinking through it is a good idea.

@josemanuel22
Copy link
Contributor

I'll take a look at it and try to upload a PR with the changes.

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

No branches or pull requests

2 participants