If a sample vector x is declared to have Rationals, the use of var() with weights promotes the final answer to a float.
MWE (Minimal working example):
julia> using StatsBase
julia> x = (1:5) // 9
5-element Vector{Rational{Int64}}:
1//9
2//9
1//3
4//9
5//9
julia> mean(x)
1//3
julia> var(x; corrected=false)
2//81
julia> w = UnitWeights{eltype(x)}(length(x))
5-element UnitWeights{Rational{Int64}}:
1
1
1
1
1
julia> var(x, w)
0.024691358024691357
julia> var(x; corrected=false) |> float # for verification
0.024691358024691357
The expected behavior is to keep the same eltype of x:
It seems the culprit is the _momentN functions in moments.jl, where s = 0.0 is set as the initial value. See, for example,
I'll probably be submitting a PR to address this in the coming days.
If a sample vector
xis declared to haveRationals, the use ofvar()with weights promotes the final answer to a float.MWE (Minimal working example):
The expected behavior is to keep the same
eltypeofx:julia> var(x, w) 2//81It seems the culprit is the
_momentNfunctions in moments.jl, wheres = 0.0is set as the initial value. See, for example,StatsBase.jl/src/moments.jl
Line 175 in 73100a0
I'll probably be submitting a PR to address this in the coming days.