Skip to content
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

BCaConfInt can't handle data with same value #40

Closed
rofinn opened this issue Jan 26, 2019 · 4 comments
Closed

BCaConfInt can't handle data with same value #40

rofinn opened this issue Jan 26, 2019 · 4 comments
Labels

Comments

@rofinn
Copy link
Contributor

rofinn commented Jan 26, 2019

Probably just needs a special case to return (t0, t0, t0)?

julia> bci = confint2(bs, BCaConfInt(0.95), 1)[1]
jkt = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
resid = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
alpha = [0.025, 0.975]
z1 = [-2.47862, 1.44131]
z0 = -0.5186569320803911
qn = [-1.95996, 1.95996]
t1 = [1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 0.857143, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 1.0, 0.857143, 1.0, 1.0, 0.857143, 0.785714, 0.928571, 0.928571, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.857143, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.857143, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 0.857143, 0.857143, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.857143, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 0.857143, 1.0, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 0.857143, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 0.928571, 0.928571, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 0.928571, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 0.857143, 1.0, 1.0, 0.857143, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.857143, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 0.857143, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.857143, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 0.857143, 0.928571, 1.0, 0.857143, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 0.928571, 1.0, 0.928571, 0.857143, 0.928571, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.857143, 0.857143, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.857143, 1.0, 0.928571, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 0.857143, 0.857143, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.857143, 0.928571, 1.0, 1.0, 1.0, 0.857143, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.785714, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.857143, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.785714, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.857143, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.857143, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 1.0, 1.0, 1.0, 0.928571, 1.0, 0.928571, 1.0, 0.928571, 1.0, 1.0, 0.928571, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0, 1.0, 0.928571, 0.928571, 1.0, 1.0, 1.0, 1.0]
zalpha = [NaN, NaN]
ERROR: InexactError: trunc(Int64, NaN)
Stacktrace:
 [1] trunc at ./float.jl:693 [inlined]
 [2] floor at ./float.jl:355 [inlined]
 [3] _quantilesort!(::Array{Float64,1}, ::Bool, ::Float64, ::Float64) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:839
 [4] #quantile!#45(::Bool, ::Function, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:811
 [5] #quantile! at ./none:0 [inlined]
 [6] #quantile!#46 at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:819 [inlined]
 [7] #quantile! at ./none:0 [inlined]
 [8] #quantile#52(::Bool, ::Function, ::Array{Float64,1}, ::Array{Float64,1}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:913
 [9] quantile(::Array{Float64,1}, ::Array{Float64,1}) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:913
 [10] confint2(::NonParametricBootstrapSample{Array{Float64,1}}, ::BCaConfInt, ::Int64) at ./REPL[75]:16
 [11] top-level scope at none:0
@juliangehring
Copy link
Owner

juliangehring commented Jan 30, 2019

Thanks for discovering this error, it certainly needs better handling! After digging into this, here are some of my thoughts:

The issue is caused because all t1s are identical, i.e. the variance of t1 is 0. The value of t0 doesn't play a role here, though it will probably equal to t1 in most case. My concern is that if t1 has no variance, reporting a confidence interval might be conceptionally questionable. @nignatiadis Can I pick your brain on that one? Does talking about a confidence interval sound ill-defined here?

On a more practical matter, other tools (such as boot in R) refuse to compute a confidence interval in such a situation. I'd also argue that if a bootstrap always yields the same value, this often indicates some issues with the data/statistic and the results should be treated with a bit of caution.

I'll need to have a closer look, and I'm happy for any input and thoughts. At the moment, I'm leaning towards

  • checking in all confidence interval methods (not only BCa) if var(t1) == 0
  • reporting an informative warning/error and/or return a confidence interval of (t0, NaN, NaN)

@nignatiadis
Copy link
Contributor

Hi @juliangehring! I think either choice is fine! Below some thoughts:

Say somebody tries to bootstrap the statistic f(x)=0.0, then maybe the interval [0.0,0.0] indeed makes sense. Similarly if the data is identical.

Of course, if such an interval is returned, it is probably questionable if this is really what the user was going after. But then again, bootstrap intervals are not always accurate anyway, there could be many reasons they might not have the right coverage, yet I still think it makes sense to return them (and the user can decide if they trust the result).

So, I would go with returning a interval of width zero, since Julia in general is not a language that tries to hold people's hands (as long as the difference to R's boot is properly documented).

But also a warning and/or NaN, NaN makes sense to me. I feel an error might be too much though.

@juliangehring
Copy link
Owner

Thanks @nignatiadis for the detailed explanation - this is a big help! In this case, let's stick with @rofinn original suggestion: Return a confidence "interval" with width 0 around t0, and don't raise a warning for now (I might reconsider this at a later point). This only changes the behaviour of the BCa confidence interval (the others implicitly behave this way), and leaves the interpretation up to the user.

@juliangehring
Copy link
Owner

Closed with #41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants