Repository navigation
ENH Contingency tables - #2418
Conversation
|
It might be best to import true division for this: @kshedden If you have an overview, then the overview documentation page would be useful, that can also point to the scipy.stats functions fisher exact and independence tests |
|
Changes Unknown when pulling 7e4c01c on kshedden:table_homog into * on statsmodels:master*. |
|
Changes Unknown when pulling d202eb1 on kshedden:table_homog into * on statsmodels:master*. |
|
Changes Unknown when pulling 749fcfe on kshedden:table_homog into * on statsmodels:master*. |
|
Changes Unknown when pulling 29a292e on kshedden:table_homog into * on statsmodels:master*. |
|
This is now partially refactored into classes. A class encapsulates several methods that can be applied to the same type of table. For example, there is a set of procedures that can be applied to a collection of 2x2 tables, so these have now become methods of the Each class has individual methods for calculating the results separately, and a summary method that calculates all results and returns a summary table object. These aren't model classes so there is no "fit" method, but otherwise they behave like model classes. |
|
I briefly browsed the classs, I was worried that it becomes too "heavy" for simple hypothesis tests. I think it looks good, it's more like Results classes than model classes. |
|
Agreed, it is intended to be lightweight. Nothing should be computed until needed. Since there are quite a few methods for contingency tables, I think it will be helpful to group them according to the high-level analysis goal or the type of input table. Some of the methods cache intermediate results that can be re-used by other methods acting on the same data. There are also some "diagnostic" methods to probe, say, where a given test result is coming from. It is easier to do this with a class than with a bunch of disconnected functions. The downside is if, say, someone is doing a simulation study and just wants 10,000 p-values, there may be a slight overhead for class creation compared to a simple function call. But I have tried to make it so that overhead is negligible. I added some |
|
Changes Unknown when pulling 12da93c on kshedden:table_homog into * on statsmodels:master*. |
There was a problem hiding this comment.
this should also have the shift_zeros=True option
|
Looks very good to me, brings the things nicely together (and is a bit similar to the weightstats classes) 3 types of comments
related is what the tests are conditioning on. (for #2605 I was looking at unconditional exact tests, that only take those numbers fixed that are fixed by the sampling design) For the current methods and results it would maybe be enough to specify what the conditioning is on. and for stats usage to specify which table and method applies for which sampling case. |
There was a problem hiding this comment.
I'm not sure anymore we have to specify under independence for each attribute.
|
I went through it again, It looks very good overall, and about ready to merge The only critical issue are the residuals, like |
|
I started to look at an example, first impression
I started to read some of Friendly's notes/vignettes for vcd, vcd-extra, and similar lecture notes by others. Some of this could go in follow-up PRs, and is not needed for this PR. |
|
I'm fine with merging when you are done with this round. I'll send a message to the mailing list for feedback after merge, and we can review some pieces again later or in the context of #2605 (two sample proportions) Also, now that I have a bit the connection I'd like to look into the relationship with loglinear/Poisson models, similar for #2605 I wanted to see how much we can replicate and have more general models with GLM Binomial (without any |
|
merged, Thanks @kshedden we will need to start a changelog for 0.8 to add big enhancements, and others |
I added several methods for contingency tables. Some of these are based on code taken from the sandbox while others are all new.
These procedures are often known by the name of their inventor, but I prefer to give names based on what they do. Stata takes a similar approach.
Here are the new procedures:
symmetry : based on code taken from sandbox ('bowker test'), assesses symmetry of the underlying joint distribution for a square table.
ordinal_association : all new code, assesses association between rows and columns that have an ordinal interpretation. It implements Agresti's "linear by linear association test", which is a generalized version of the Cochran-Armitage trend test. Basically a Pearson chi^2 test for ordinal tables.
stratified_association : all new code, implements the "Cochran-Mantel-Haenszel test" and associated estimate and CI's for the common odds ratio in a set of stratified 2x2 tables.
homogeneity : all new code, compares row and column marginal distributions for a square table. Generalizes McNemar's test to two factors with more than two levels.
mcnemar : pulled from sandbox, special case of homogeneity test for 2x2 tables
cochrans_q : pulled from sandbox, generalization of McNemar's test to multiple factors with two levels each.
Design issues:
All functions take a contingency table as the input. There is no facility for passing in the data itself. The table can be an ndarray or Pandas.
Most functions have the option of returning multiple return values or a bunch. In many cases the bunch contains additional information not available otherwise. There are no proper results classes here.
Test coverage is decent but it uses "nice" data sets. There is little testing for corner cases or pathological examples (e.g. all zeros, non-integers, negative values).
Missing pieces:
This is a large area so this is far from complete. There is very little "exact inference" here, and no special facilities for large and/or sparse tables.
References:
R "coin" package : http://cran.r-project.org/web/packages/coin/coin.pdf
Stata : http://www.stata.com/manuals13/rsymmetry.pdf
SAS : http://www2.sas.com/proceedings/forum2008/382-2008.pdf
R Mantel-Haenszel : https://stat.ethz.ch/R-manual/R-devel/library/stats/html/mantelhaen.test.html
Background about common odds ratios : http://www.biostat.umn.edu/~dipankar/bmtry711.11/lecture_15.pdf
http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mantel.htm