Skip to content

ENH: Add abstract class for returning test results. - #1182

Closed
jseabold wants to merge 2 commits into
statsmodels:masterfrom
jseabold:test-results-class
Closed

jseabold wants to merge 2 commits into
statsmodels:masterfrom
jseabold:test-results-class

Conversation

@jseabold

Copy link
Copy Markdown
Member

Food for thought? Alternatively, we could have a wrapper that returns a DataFrame similar to the ANOVA results.

Run the file to see output for Augmented Dickey Fuller for example.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling 4a0b574 on jseabold:test-results-class into 9d4b1f8 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

Something like this could be pretty much the default.

Maybe a more basic Bunch as minimalistic (super) class (I copied that in many different modules already).

Then details: add the name of the test, do we really make H0, H1 required?
add distribution (is already in **kwds)
look at Stata for details

I started stats/base.py as location for results classes.
I also made lots of changes to ContrastResults
https://github.com/josef-pkt/statsmodels/compare/robust_cov#diff-7

@jseabold

Copy link
Copy Markdown
Member Author

I didn't want the Bunch because we don't want to have to provide attribute access for the keywords. Then we could only have Python-ok keywords and this is too restrictive I think. The idea is very similar though.

I don't know about H0/H1/HA. I thought you might have some input here. I really, really like having this in the test results, so I don't have to check the docs. But it's not always even in the docs, so that's why I made it required. You can't use this if you don't document it, but it might be enough to only require the null? I dunno.

@josef-pkt

Copy link
Copy Markdown
Member

I almost only use attribute access, typing [" "] is too much work, plus we have tab completion on attribute access, often I don't bother about the dictionary access to my "Holder" storage classes
So, I'm strongly in favor of attribute access, I didn't run into any python-only keyword problems yet. Plus it reduces the spelling ambiguities, "p value" "p-value" p_value

I think we include the H0, H1, but I'm not sure I want to hard code them in a subclass instead of giving it as an argument. (might be a minor point).
In some cases, H0 and H1 might be vague, unless we want to get very technical, for example for general specification tests.

BTW: I'm soon finished reading my way through the specification and testing chapters in Cameron Trivedi's count data book. I'm soon ready to write a series of diagnostic tests applicable to discrete and GLM.
Some of the diagnostic tests will need more model specific information from the results or model, and more informative TestResults strings to indicate what the hypothesis test is based on, (robust covariances for example)
I'm thinking whether it's not better keeping some of the stats.diagnostics tests generic and add methods to the results classes
.
For example I was trying out het_breushpagan with pearson residuals after Poisson, which works because het_breushpagan just takes residuals.
(AFAICS to be able to use mean corrected raw residuals, which Cameron Trivedi do in a similar test, breush-pagan needs to handle heteroscedasticity.)

BTW: Cameron Trivedi's count data book, chapters 2 and 6 are a very good read (after I struggled through some of this for the "generic" cases in Econometrica articles).

@jseabold

Copy link
Copy Markdown
Member Author

You don't actually need to do anything other than type summary(), and I wasn't really excited about renaming expressive things like "1% critical value" to one_percent_critical_value.

I don't understand what you mean hard-code in a subclass? You just return Wrapper("Null Hypothesis: ...", ...).

Yes, I like Cameron and Trivedi's book. Wooldridge is also pretty good at tying these things together.

@josef-pkt

Copy link
Copy Markdown
Member

I don't understand what you mean hard-code in a subclass?

Many cases won't fit a general abstract TestResults class, and in many cases I want to write a more personalized summary with appropriate methods. So I was thinking of creating at least a small hierarchy of TestResults classes.

typing results["1% critical value"] won't be much fun either, especially if you have to look up the spelling first with print results.keys()

To the content of the TestResults classes:
I think they should be "smart", and be able to calculate things like critical values on their own. AFAICS, neither R nor Stata stores all the attributes that are printed in a summary
for example the ContrastResults after a t_test (with t or normal distribution) calculates besides p-values also confidence intervals (in my branch).

@jseabold

Copy link
Copy Markdown
Member Author

I added acorr_box_test to this PR that uses TestResult. This somewhat duplicates the functionality of acorr_ljunbox in statsmodels.sandbox.stats.diagnostic, but it's a little more to the point. Uses FFT for ACF, only calculates Q for needed lag, and allows the degreees of freedom correction needed for ARMA models.

@josef-pkt josef-pkt added the PR label Feb 19, 2014
@jseabold jseabold mentioned this pull request Mar 28, 2014
@jseabold

jseabold commented Apr 8, 2014

Copy link
Copy Markdown
Member Author

See #277.

@springcoil

Copy link
Copy Markdown

Can this be added into master soon? I see no reason this isn't yet.

@josef-pkt

Copy link
Copy Markdown
Member

I keep postponing the general refactoring of hypothesis test returns. It's still case by case.

latest discussion in #2725

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.

4 participants