Skip to content

ignoring elements with 0 weight #492

@tpapp

Description

@tpapp

Thanks to #316, quantile now ignores elements with a 0 weight. I wonder if the same would make sense for other functions, particularly mean and std. Currently

julia> using StatsBase

julia> w = Weights([0, 1, 1]);

julia> x = [Inf, 1, 1];

julia> mean(x, w)
NaN

julia> std(x, w, corrected = false)
NaN

julia> quantile(x, w, [0.5])
1-element Array{Float64,1}:
 1.0

My motivation for this is working with data where I am calculating statistics of some x ./ y, weighted by y. When y == 0, the ratio is nonsensical, but at the same time weighting should make it irrelevant. Instead, now the NaN propagates.

This is nothing I cannot work around, it would just make my workflow more convenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions