@@ -42,7 +42,7 @@ function (ecdf::ECDF)(v::AbstractVector{<:Real})
4242end
4343
4444"""
45- ecdf(X; weights::AbstractWeights )
45+ ecdf(X[ ; weights::AbstractVector{<:Real}] )
4646
4747Return an empirical cumulative distribution function (ECDF) based on a vector of samples
4848given in `X`. Optionally providing `weights` returns a weighted ECDF.
@@ -53,12 +53,17 @@ evaluate CDF values on other samples.
5353`extrema`, `minimum`, and `maximum` are supported to for obtaining the range over which
5454function is inside the interval ``(0,1)``; the function is defined for the whole real line.
5555"""
56- function ecdf (X:: AbstractVector{<:Real} ; weights:: AbstractVector{<:Real} = Weights (Float64[]))
56+ function ecdf (X:: AbstractVector{<:Real} ; weights:: AbstractVector{<:Real} = weights (Float64[]))
5757 any (isnan, X) && throw (ArgumentError (" ecdf can not include NaN values" ))
58- isempty (weights) || length (X) == length (weights) || throw (ArgumentError (" data and weight vectors must be the same size," *
59- " got $(length (X)) and $(length (weights)) " ))
60- ord = sortperm (X)
61- ECDF (X[ord], isempty (weights) ? weights : Weights (weights[ord]))
58+ _weights = weights isa AbstractWeights ? weights : StatsBase. weights (weights)
59+ if isempty (_weights)
60+ return ECDF (sort (X), _weights)
61+ else
62+ length (X) == length (_weights) || throw (ArgumentError (" data and weight vectors must be the same size," *
63+ " got $(length (X)) and $(length (_weights)) " ))
64+ ord = sortperm (X)
65+ ECDF (X[ord], _weights[ord])
66+ end
6267end
6368
6469minimum (ecdf:: ECDF ) = first (ecdf. sorted_values)
0 commit comments