Skip to content

Fix conversion error in proportion_confint - #2935

Merged
josef-pkt merged 2 commits into
statsmodels:masterfrom
BrianLondon:master
May 30, 2016
Merged

josef-pkt merged 2 commits into
statsmodels:masterfrom
BrianLondon:master

Conversation

@BrianLondon

Copy link
Copy Markdown
Contributor

Adjusted upper and lower bounds to the optimizer when using the 'binom_test' method for proportion_confint to solve the brentq fails ValueError: f(a) and f(b) must have different signs error. Also, enforced bounds out to 0.0 or 1.0 in the case where that's the ML estimate.

Adjusted upper and lower bounds to the optimizer
when using the 'binom_test' method for
proportion_confint
@josef-pkt

Copy link
Copy Markdown
Member

Thanks,

Do you have an example for the brentq failure?

First the changes are an improvement over the existing code, so are fine to merge.

However, I added inversion of binom test as an "obvious method to try", but I don't remember having seen a reference for it.
The standard "exact" confidence interval is "beta", i.e. Clopper-Pearson.

(AFAIU: inverting the binom_test results in exact score confidence intervals)

I just checked inversion of binom test doesn't have unit tests, IIRC because it's not available in what I used as reference package.

@josef-pkt

Copy link
Copy Markdown
Member

Reading through the comments and the docstring shows that I ran into this problem also. So this fix looks good and should solve that problem.

Second issue in the code comments is whether the discreteness of the binomial sample space messes up the rootfinding.
To check: are inverting binomial test supposed to be the same as Cloppe-Pearson (fiducial)
Another thing that I learned since I wrote the code and just remembered. binom_test in scipy is not centered. see #2735 for different versions, and more references to check on this.

@josef-pkt

Copy link
Copy Markdown
Member

@BrianLondon As explanation to my comments:

My comments are mostly not directly related to this PR. I wrote the function initially essentially by translating formulas into code. In the meantime, I worked on several related questions, and have a better overview over the different methods for constructing hypothesis tests and confidence intervals.

All the other methods here are standard, but I need to come back to the binom_test version to check the details (definition and theory).

@josef-pkt josef-pkt added this to the 0.8 milestone May 11, 2016
Comment thread statsmodels/stats/proportion.py Outdated
# TODO: check if we should round up or down, or interpolate
if count == 0:
ci_low = 0
else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: missing, TravisCI errors

@BrianLondon

Copy link
Copy Markdown
Contributor Author

Yeah, I would support continuing to label the method "experimental" in the docstring lacking any citations to back up the method. I can add binom inverse to the unit tests ad add a test that generates the error on the old code to avoid regressions in the future.

Like I said, I don't know of any citations to validate the method, but I'm pretty sure there is a function in MATLAB that does the same thing. I can try to track it down.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.004%) to 85.399% when pulling de62105 on BrianLondon:master into de15ec8 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

Yes, having at least a regression test for this would be good.

Also, it would be helpful if you could find the matlab function. However, the Fay references in #2735 and related might cover this case. I didn't make the connection to this when I looked at Fay, because that was mostly related to two sample proportion tests and confint.

@josef-pkt

Copy link
Copy Markdown
Member

merging as is
I added a comment to 2735 to look at this some more
#2735 (comment)

@josef-pkt
josef-pkt merged commit 08884cf into statsmodels:master May 30, 2016
@josef-pkt

Copy link
Copy Markdown
Member

@BrianLondon Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants