Repository navigation
Conversation
|
An example of output can be obtained with e.g., if __name__ == "__main__":
stats = Statistics(t=1.96, R=1.00) # a list of test results
hypothesis = Hypothesis(null="Null hypothesis",
alternative="Something else")
crit_vals = CriticalValues({"5%": 0.9, "10%": 1.5})
result = TestResult("Example test", hypothesis, stats, crit_vals)
print(result)Which returns, |
|
I think a more likely location is statsmodels.stats.base We need some optional attributes that can be listed by default after the main attributes, e.g. attributes in my latest Also in most cases we don't specify critical values but report p-values and include the distribution, e.g. normal, t, F, chi2. In those cases we can leave critical values at None and don't print them. |
|
My current thinking is to then maintain a list of optional fields on a TestResult instance, such that each individual test can mix-and-match where appropriate. This way we ensure test results remain flexible, but also adhere to a common structure. I've updated my code with one way to do so. My idea is to introduce lightweight classes for all relevant test information (e.g. for the confidence interval, or the distribution, and perhaps one |
And an idea for preserving interface compatibility for tests
| if key in TestResult._options: | ||
| setattr(self, key, value) | ||
|
|
||
| def __getattr__(self, item): |
There was a problem hiding this comment.
My thinking here is to preserve interface compatibility between old-style test results (e.g. Bunch, or ResStore) and new-style tests where possible. I intend Statistics to be a new-style store object, against which the TestResult will always check if the attribute cannot be found on itself.
If it is found in the statistics attribute, the item there is returned and a DepreciationWarning is raised explaining the new behaviour. This way we can start using the new-style test results without breaking too much of existing, external code.
|
@josef-pkt I'll start writing docstrings soon, explaining the design/intended use. For now, I've replaced several ResultStores and the like in various tests. Do you have suggestions where to look next? I'd love to extend the number of use cases this As an aside the linter seems to think, def test_raises_missing_value_access(self):
with assert_raises(AttributeError):
self.test_result.some_missing_statistichas no effect (L104 in |
|
It might be worth looking at how arch does this. A lot of thought went into that. |
I'll have a look at that later today. |
Codecov Report
@@ Coverage Diff @@
## master #5001 +/- ##
==========================================
- Coverage 81.75% 81.41% -0.35%
==========================================
Files 569 583 +14
Lines 89824 90253 +429
Branches 10022 10111 +89
==========================================
+ Hits 73440 73476 +36
- Misses 14117 14468 +351
- Partials 2267 2309 +42
Continue to review full report at Codecov.
|
|
This should be merged early in 0.11 release cycle, so we can add more usage of it in existing hypothesis tests and see how well it works. |
|
@josef-pkt I agree, but before then I'd like to continue working on it for a bit - there's some additional ideas I want to test, but I have not yet had the time to implement (including the optional unpacking for backwards compatibility that I'd like to test some more and implement in more places). I should be able to make the time during my upcoming Christmas break. |
|
Thanks, |
|
I recently realised I never did quite finish this. I have some time over the summer, and hope to continue this then (might refactor some of this as I have a couple of new ideas on how to proceed). One thing I'd like to do is make the return of a test object non-optional. Code that currently depends on the return of a tuple may still be supported by having the test object unpack itself if requested, by say making the test object inherit from |
|
FYI: the default class for hypothesis test and similar returns is now a |
Following #4994, which references to i.a. #1182, I decided to open a new PR for this issue. While #1182 aspires to mostly the same thing, it appears largely stale. I intend to use this base class in multiple places, and have several locations inherit from, or directly use this base class.
After that is set-up, a next step will be to consolidate the children classes and negotiate a proper protocol per module (e.g., the
tsatests might need a different parent class than do mostregressiontests and the like).@josef-pkt input is much appreciated! :)