Skip to content

Commit

Permalink
Fix ecdf bugs
Browse files Browse the repository at this point in the history
Corrects output of  ecdf in the case where there are no values in X
between two values in v and the case where all values in X were less
than multiple values in v.
  • Loading branch information
simonster committed Aug 30, 2013
1 parent 2a9e325 commit 5990d2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/others.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/01.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

0 comments on commit 5990d2b

Please sign in to comment.