-
Notifications
You must be signed in to change notification settings - Fork 195
Open
Description
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.024691358024691357The expected behavior is to keep the same eltype of x:
julia> var(x, w)
2//81It seems the culprit is the _momentN functions in moments.jl, where s = 0.0 is set as the initial value. See, for example,
Line 175 in 73100a0
| s = 0.0 |
I'll probably be submitting a PR to address this in the coming days.
Metadata
Metadata
Assignees
Labels
No labels