diff --git a/src/others.jl b/src/others.jl index fa85f56586187..cbdfd3e9ba068 100644 --- a/src/others.jl +++ b/src/others.jl @@ -81,14 +81,17 @@ function ecdf{T}(X::AbstractVector{T}) r0 = 0 i = 1 for x in Xs - if x > v[ord[i]] + while i <= m && x > v[ord[i]] r[ord[i]] = r0 i += 1 end r0 += 1 if i > m break end end - if i == m r[ord[i]] = n end + while i <= m + r[ord[i]] = n + i += 1 + end return r / n end return e diff --git a/test/01.jl b/test/01.jl index 6f8f7a3f42245..6a4a3f81d1db0 100644 --- a/test/01.jl +++ b/test/01.jl @@ -28,3 +28,6 @@ fnecdf = ecdf(randn(10000000)) @test_approx_eq_eps fnecdf([-1.96, -1.644854, -1.281552, -0.6744898, 0, 0.6744898, 1.281552, 1.644854, 1.96]) [0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.975] 1e-3 @test_approx_eq_eps fnecdf(1.96) 0.975 1e-3 @test_approx_eq fnecdf([-1.96, -1.644854, -1.281552, -0.6744898, 0, 0.6744898, 1.281552, 1.644854, 1.96]) map(fnecdf, [-1.96, -1.644854, -1.281552, -0.6744898, 0, 0.6744898, 1.281552, 1.644854, 1.96]) + +fnecdf = ecdf([0.5]) +@test fnecdf([zeros(5000), ones(5000)]) == [zeros(5000), ones(5000)]