Skip to content

Conversation

this-josh
Copy link

As discussed here currently if you pass a matrix to describe you get an error from quantile!

julia> describe(reshape(collect(1:100), (10, 10)))
ERROR: MethodError: no method matching quantile!(::Matrix{Int64}, ::Vector{Float64}; sorted=false, alpha=1.0, beta=1.0)
Closest candidates are:
  quantile!(::AbstractArray, ::AbstractVector, ::AbstractArray; sorted, alpha, beta) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:936
  quantile!(::AbstractVector, ::Union{Tuple{Vararg{Real}}, AbstractArray}; sorted, alpha, beta) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:953
Stacktrace:
 [1] quantile(itr::Matrix{Int64}, p::Vector{Float64}; sorted::Bool, alpha::Float64, beta::Float64)
   @ Statistics /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:1070
 [2] quantile(itr::Matrix{Int64}, p::Vector{Float64})
   @ Statistics /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Statistics/src/Statistics.jl:1070
 [3] summarystats(a::Matrix{Int64})
   @ StatsBase ~/.julia/packages/StatsBase/pJqvO/src/scalarstats.jl:915
 [4] describe(io::Base.TTY, a::Matrix{Int64})
   @ StatsBase ~/.julia/packages/StatsBase/pJqvO/src/scalarstats.jl:943
 [5] describe(x::Matrix{Int64})
   @ StatsBase ~/.julia/packages/StatsBase/pJqvO/src/scalarstats.jl:941
 [6] top-level scope
   @ REPL[3]:1

I made a small change which vectorises a matrix and provides a description for the whole matrix.

julia> describe(reshape(collect(1:100), (10, 10)))
Summary Stats:
Length:         100
Missing Count:  0
Mean:           50.500000
Minimum:        1.000000
1st Quartile:   25.750000
Median:         50.500000
3rd Quartile:   75.250000
Maximum:        100.000000
Type:           Int64

In the future a dims argument could be useful.

@nalimilan
Copy link
Member

Thanks! However I think we'd better change quantile in Statistics to accept any AbstractArray, rather than working around this limitation downstream. Would you make a PR in Statistics?

@JoshKImperial
Copy link

Sure, I'll look into this making a PR in Statistics

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

Successfully merging this pull request may close these issues.

3 participants