StatsBase.jl icon indicating copy to clipboard operation
StatsBase.jl copied to clipboard

Compute statistics along dimensions

Open lindahua opened this issue 11 years ago • 5 comments

It is useful to compute certain statistics along specific dimensions. I open this thread to derive the development along this line.

  • [ ] skewness
  • [ ] kurtosis
  • [ ] moment
  • [ ] entropy
  • [ ] geomean
  • [ ] harmmean
  • [ ] variation
  • [ ] sem

Some other functions like mode and quantile require more sophisticated data structure to compute, and thus not included in this list. We may look at those in future.

lindahua avatar Jun 23 '14 14:06 lindahua

+1 if you mean something like this:

StatsBase.trimmean{T}(v::AbstractArray{T}, p, region) = mapslices(x->trimmean(x,p), v, region)

bjarthur avatar Jul 14 '15 16:07 bjarthur

Any progress on this?

jamblejoe avatar Jun 08 '20 13:06 jamblejoe

Now that Julia provides these, it is probably be better to use e.g. skewness.(eachrow(x)) and skewness.(eachcol(x)). The dims=1/dims=2 approach requires adjusting lots of methods and is less explicit.

nalimilan avatar Jun 20 '20 15:06 nalimilan

It would be nice to have functions like skewness(A; dims) taking a dims keyword to reduce over, where A can be a general N-dimensional Array. Any plans to implement this?

cossio avatar Jun 27 '20 10:06 cossio

@cossio There's a PR to add a generic eachslice iterator to Base: https://github.com/JuliaLang/julia/pull/32310; it's been under review for a while but there's recent activity...

kleinschmidt avatar Jan 29 '21 19:01 kleinschmidt

This is now merged, time to close this issue?

nilshg avatar Mar 28 '23 14:03 nilshg

skewness(rand(10,10), dims=1) doesn't work on 1.9rc1 and latest StatsBase

jamblejoe avatar Mar 28 '23 20:03 jamblejoe

@jamblejoe but you can use eachslice on julia 1.8 to achieve the same:

julia> skewness.(eachslice(rand(10,10), dims=1))
10-element Vector{Float64}:
 -0.357654736525527
 -0.06636393783605732
 -0.20782459433865907
  1.25151036890323
  0.13408296667729347
 -0.4302398373636257
 -0.14363707095203634
 -0.00889806440269636
 -0.6370034546305223
  0.5832296811450159

bjarthur avatar Mar 28 '23 21:03 bjarthur

@bjarthur works thanks! Can be closed from my side

jamblejoe avatar Mar 28 '23 22:03 jamblejoe