-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add signrank distribution #173
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #173 +/- ##
==========================================
+ Coverage 62.99% 66.71% +3.72%
==========================================
Files 14 15 +1
Lines 635 712 +77
==========================================
+ Hits 400 475 +75
- Misses 235 237 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I'd try to add it to test/rmath.jl` similarly to Lines 233 to 241 in 8f50565
|
e63bf83
to
fb4cedc
Compare
Some differences with R remain: julia> signrankinvcdf(4, 0.0)
0.0
julia> signrankinvlogcdf(4, log(0))
0.0
julia> qsignrank.(0.0,4,true,false)
0.0
julia> qsignrank.(log(0.0),4,true,true)
NaN Rounding in the quantiles is also an issue: julia> qsignrank.(-2.1,4,true,true)
1.0
julia> qsignrank.(-2.0794415416798357,4,true,true)
1.0
julia> qsignrank.(-2.0,4,true,true)
2.0
julia> signrankinvlogcdf(4,-2.1)
1.0
julia> signrankinvlogcdf(4,-2.0794415416798357)
2.0
julia> signrankinvlogcdf(4,-2.0)
2.0 The true cdf jumps at 0.125, but that value does not roundtrip with exp/log. julia> exp(-2.0794415416798357)
0.12500000000000003
julia> log(0.125)
-2.0794415416798357
julia> exp(log(0.125))
0.12500000000000003 |
I improved rounding by getting rid of all |
Stuck on this: for higher julia> psignrank(1,4,true,false)
0.125
julia> qsignrank(0.125,4,true,false)
1.0
julia> signrankinvcdf(4,0.125)
1.0
julia> psignrank(1,50,true,false)
1.776356839400249e-15
julia> qsignrank(1.776356839400249e-15,50,true,false)
0.0
julia> signrankinvcdf(50,1.776356839400249e-15)
1.0 julia> qsignrank.(psignrank.(-1:8,4,true,false),4,true,false)
10-element Vector{Float64}:
0.0
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
julia> qsignrank.(psignrank.(-1:8,50,true,false),50,true,false)
10-element Vector{Float64}:
0.0
0.0
0.0
0.0
2.0
3.0
5.0
6.0
7.0
8.0 Our own version does not have this issue: julia> signrankinvcdf.(50,signrankcdf.(50,-1:8))
10-element Vector{Float64}:
0.0
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0 |
Would be good to file a bug report in the R bug tracker https://bugs.r-project.org/. Here you can avoid testing these cases against R for now and instead test some invariants such that the round tripping of p and q. |
e3e0ed4
to
166d57f
Compare
Seems like windows/mac have slightly different rounding going on somewhere? For the older julia versions, what would be the best way to round to nearest integer? |
test/rmath.jl
Outdated
@test signrankinvcdf.(10, signrankcdf.(10, -1:56)) ≈ [0; 0:55; 55] atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvccdf.(10, signrankccdf.(10, -1:56)) ≈ [0; 0:55; 55] atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvlogcdf.(10, signranklogcdf.(10, -1:56)) ≈ [NaN; 0:55; 55] nans = true atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvlogccdf.(10, signranklogccdf.(10, -1:56)) ≈ [0; 0:54; NaN; NaN] nans = true atol = 1e-12 rtol = 1e-12 | ||
|
||
@test signrankinvcdf.(50, signrankcdf.(50, -1:1276)) ≈ [0; 0:1275; 1275] atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvccdf.(50, signrankccdf.(50, -1:1276)) ≈ [0; 0:1275; 1275] atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvlogcdf.(50, signranklogcdf.(50, -1:1276)) ≈ [NaN; 0:1275; 1275] nans = true atol = 1e-12 rtol = 1e-12 | ||
@test signrankinvlogccdf.(50, signranklogccdf.(50, -1:1276)) ≈ [0; 0:1274; NaN; NaN] nans = true atol = 1e-12 rtol = 1e-12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to compare evaluations for each value separately to avoid that differences are masked by some large values. All existing tests seem to loop over the desired inputs.
This failure is unique to ubuntu: |
2be8bbe
to
64f2263
Compare
This is what is causing test failures: julia> psignrank(18,10,false,true) # windows
-0.2076393647782445
julia> psignrank(18,10,false,true) # linux
-0.20763936477824452 |
Implementation of the signrank distribution.
The
cdf
is heavily optimized, since that is what is needed for the popular hypothesis test associated with this distribution.The testing in this package seems quite involved, I could use some pointers on where to add the tests.