Skip to content

Commit

Permalink
Merge pull request JuliaLang#21 from simonster/ecdf
Browse files Browse the repository at this point in the history
Fix ecdf bugs
  • Loading branch information
johnmyleswhite committed Aug 30, 2013
2 parents 2127b21 + 5990d2b commit 5f298c9
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 5f298c9

Please sign in to comment.