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

mean_and_std does not support Tuple but the documentation says so

Open melioristic opened this issue 2 years ago • 7 comments

https://github.com/JuliaStats/StatsBase.jl/blob/08d4b77a4b42ef8cadb67b98da65e7fbd9959e0b/src/moments.jl#L168-L177

Hey everyone! I am new to Julia, and was trying to use the function mean_and_std(). The documentation says that it can take a tuple as input but did not see such a function in the source code. That is why I see an error for this code. using StatsBase X = ones((3,4,5)) mean_and_std(X, dim=(1,2))

And the error is ERROR: MethodError: no method matching mean_and_std(::Array{Float64, 3}; dim=(1, 2)). It would be a couple of lines of code to implement it. I can create a PR if you think that my understanding is correct.

melioristic avatar Jun 09 '22 13:06 melioristic

the issue is the following, in moments.jl

function mean_and_std(x::RealArray, dim::Int; corrected::Bool=true)
    m = mean(x, dims=dim)
    s = std(x, dims=dim, mean=m, corrected=corrected)
    m, s
end

and

function mean_and_std(x::RealArray, w::AbstractWeights, dims::Int;
                      corrected::DepBool=nothing)
    m = mean(x, w, dims=dims)
    s = std(x, w, dims, mean=m, corrected=depcheck(:mean_and_std, :corrected, corrected))
    m, s
end

They do not allow dim/dims to be as tuples in mean_and_std. Removing ::Int may help?

yangcht avatar Jun 09 '22 19:06 yangcht

Yes we should deprecate the dim positional argument and add a dims::Any keyword argument instead. Would you be willing to make a pull request?

nalimilan avatar Jun 10 '22 19:06 nalimilan

I have created a pull request

yangcht avatar Jun 10 '22 20:06 yangcht

any updates?

yangcht avatar Jul 26 '22 21:07 yangcht

Maybe there was confusion. I was not doing it. I can only do this in the first week of August. Can update by the 7th of August.

melioristic avatar Jul 27 '22 07:07 melioristic

Maybe there was confusion. I was not doing it. I can only do this in the first week of August. Can update by the 7th of August.

Sorry. I meant that I was trying to create a pull request by needing some help.

yangcht avatar Jul 27 '22 09:07 yangcht

I closed the pull request because I need a bit more time to understand how to modify the weighted std/var considering the same issue of supporting the tuple type as dimensions.

yangcht avatar Aug 01 '22 09:08 yangcht