Repository navigation
BUG: Center CompareMeans summary CI on the null - #11260
Open
xihaian251 wants to merge 2 commits into
Open
xihaian251 wants to merge 2 commits into
xihaian251 wants to merge 2 commits into
Conversation
| statistic, pvalue = cm.ztest_ind(usevar=usevar, value=2) | ||
| lower, upper = cm.zconfint_diff(usevar=usevar) | ||
|
|
||
| assert_allclose(statistic, expected[:, 2], rtol=1e-13) |
| lower, upper = cm.zconfint_diff(usevar=usevar) | ||
|
|
||
| assert_allclose(statistic, expected[:, 2], rtol=1e-13) | ||
| assert_allclose(pvalue, expected[:, 3], rtol=1e-13) |
| # Confidence-interval methods remain intervals for the raw mean | ||
| # difference; only the summary presentation is null-centered. | ||
| raw_expected = _comparemeans_direct(x1, x2, use_t, usevar, value=0) | ||
| assert_allclose(lower, raw_expected[:, 4], rtol=1e-13) |
| # difference; only the summary presentation is null-centered. | ||
| raw_expected = _comparemeans_direct(x1, x2, use_t, usevar, value=0) | ||
| assert_allclose(lower, raw_expected[:, 4], rtol=1e-13) | ||
| assert_allclose(upper, raw_expected[:, 5], rtol=1e-13) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NumPy's guide.
Problem
With a nonzero value, CompareMeans.summary reports the coefficient on the scale mean1 - mean2 - value, but reports the confidence interval on the unadjusted mean-difference scale. Consequently, the reported coefficient and confidence interval describe different quantities.
For the default two-sample t test, the reported coefficient is -1.0000, but the pre-fix confidence interval is [-2.345, 4.345], centered at +1. On the reported coefficient scale, the interval should be [-4.345, 2.345].
Changes
Subtract value from both confidence-interval endpoints in summary, so that the coefficient and its interval both describe the restriction mean1 - mean2 - value.
This changes the summary presentation only. The underlying t and z tests, their statistics and p-values, and the confidence-interval methods for the raw mean difference are unchanged. The default value=0 summary is also unchanged.
Tests
The regression tests compare summary rows with independent closed-form calculations across t and z tests, pooled and unequal variances, one- and two-dimensional inputs, and zero and nonzero null values. Additional tests verify the underlying inference methods and the default summary output.
Local validation: 107 tests passed.
Affected test module: statsmodels/stats/tests/test_weightstats.py.
AI Disclosure
Contributions must comply with the statsmodels AI Policy.
Tick exactly one of the following. If AI tools were used, replace the
<...>placeholders in the second option with the tool name(s) and how the tool's output was
used.
Tool(s): Qoder, ChatGPT.
Used for: Qoder: patch implementation, regression tests, debugging and local verification; ChatGPT: source investigation, defect analysis and technical review.
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.