Skip to content

ENH: multivariate mean tests and confint - #4107

Merged
josef-pkt merged 2 commits into
statsmodels:masterfrom
josef-pkt:multivariate_stats
May 7, 2020
Merged

josef-pkt merged 2 commits into
statsmodels:masterfrom
josef-pkt:multivariate_stats

Conversation

@josef-pkt

@josef-pkt josef-pkt commented Nov 6, 2017 •

Copy link
Copy Markdown
Member

see e.g. #3208

I thought I already wrote something like this but don't find anything.
This is currently just a short exercise writing some basic multivariate mean tests to get started.

plans for implementation

There is a lot of repeated computation if we provide and use separate function that all start from data. Those standalone functions are good to get started but need better structure.
Most likely the pattern will or should follow weightstats with a mixture of classes and standalone functions. One useful pattern is to have the functions based on summary statistics, so we have to compute those only once.

Reference for this time is Johnson and Wichern Applied Multivariate Statistical Analysis 6th edition. (I started to browse it by chance.)

Stata mvtests has good functions with almost complete formulas. However, I didn't see anything about mv confidence intervals. The simulataneous confidence intervals here use an example from Johnson and Wickern. They look similar to or the same as the Sheffe intervals added by Kerby.
Pointwise confidence intervals are compared to weightstats.

Stata doesn't have any kurtosis correction in mvtests, AFAICS. (see elliptical issues)

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.005%) to 81.894% when pulling 82720ce on josef-pkt:multivariate_stats into 8b83bc3 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

I guess there is no __future__ in python 2.7, Travis fails with it.
(One more year before saying byebye, see numpy mailing list)

@josef-pkt

josef-pkt commented Nov 7, 2017 •

Copy link
Copy Markdown
Member Author

a comment about the df in the F test, and TODO in unit tests:
Stata uses the number of linear combinations as df in the test of linear hypothesis.
I'm basing df on k_vars.
I'm not sure this is correct, but there is a difference between Sheffe type (e.g. of confidence intervals) which maintain the size for any linear combination, while the standard F/Wald test is for the specific joint hypothesis.

that is, we have (e.g. for confidence intervals):
(i) Sheffe: maintain size for all possible tests (of linear combination of parameters)
(ii) subset: maintain size for a specific set of tests
(iii) individual/point wise: maintain size for a single non-composite hypothesis

my guess is that Stata does (ii) while I do (i) following Johnson and Wichern, but I might have it still wrong. (I didn't try to understand the math for the different cases. The second point is that we also vectorize individual tests as in t_test, which are not joint tests but for simultaneous confint we want to correct for multiple testing.)
#2955 #790 #2172 related on simultaneous confidence intervals and Sheffe

edit
Johnson and Wichern, p.232 eq. (5.29) and before: Bonferroni corrected confidence intervals given the specific number of hypothesis.

@jbrockmendel

Copy link
Copy Markdown
Contributor

@josef-pkt I'll be happy to look this over if review will be useful. Kinda at a loss for how to contribute these days.

@josef-pkt

Copy link
Copy Markdown
Member Author

@jbrockmendel It's a bit early to review this.

We need functionality like this and similar. But the occasion was writing code that is relatively limited and can be done in a few hours when I have time. I was only reading and opening issues in the last round in this area, at least I don't find any code.

@josef-pkt

Copy link
Copy Markdown
Member Author

amended with division from the future

@coveralls

coveralls commented Nov 7, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.008%) to 87.747% when pulling 40df01f on josef-pkt:multivariate_stats into 38a0791 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

will need rebase when working on this again
(appveyor fails on unrelated compat issue that is fixed in master)

Comment thread statsmodels/stats/multivariate.py Outdated
mean or their linear transformation, center of the confidence region


Result 5.3 page 225

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What is the reference here?
no reference to a book or article in code/docstrings

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Johnson and Wichern 6th edition, mentioned in the PR description

@josef-pkt

josef-pkt commented Dec 31, 2018 •

Copy link
Copy Markdown
Member Author

These look like nice simple functions that we should be able to merge independent of more elaborate enhancements (I don't remember right now what I had in mind. One related application area that I looked at, are control charts).
unit test coverage looks ok based on a brief skimming of those.

@josef-pkt

Copy link
Copy Markdown
Member Author

It looks like simultaneous confint could be used for prediction in models based on params and cov_params, mv_mean_conf_int_simult_stat
(names have too many underlines/words)

@josef-pkt
josef-pkt force-pushed the multivariate_stats branch from b3ecbf9 to 27d1f86 Compare May 6, 2020 15:01
@pep8speaks

pep8speaks commented May 6, 2020 •

Copy link
Copy Markdown

Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-05-07 14:20:36 UTC

@josef-pkt

Copy link
Copy Markdown
Member Author

rebased

@josef-pkt

Copy link
Copy Markdown
Member Author

no failures besides lint
mv_mean_conf_int_simult has no unit test coverage

@josef-pkt

josef-pkt commented May 6, 2020 •

Copy link
Copy Markdown
Member Author

this PR only includes 1-sample test and confidence interval

Stata mvtest means includes k-sample test of equal means under homoscedasticity and heteroscedasticity. (technical details looks good)

In Stata 2-sample and k-sample mv tests use the same interface (function call) but algorithm differs under heteroscedasticity.
k-sample test under homoscedasticity (constant cov) delegates to MANOVA, under unequal cov, the algorithms look a bit similar to Welch type t and oneway tests with df correction.

@josef-pkt

Copy link
Copy Markdown
Member Author

possible merge the two confint function and add keyword simult or simultaneous
simultaneous is more difficult to spell

test_mvmean_1samp
confint_mvmean_1samp
question: onesided alternative, Stata doesn't have it but I guess we could add it with elementwise inequality (maybe that could become similar to oneway max diff equivalence testing (not Included in anova PR))

and to add
test_mvmean_ksamp or better oneway_mvmean (similar to anova/robust stats PR)
(I guess there could be also the equivalence test similar to oneway anova)

maybe (Stata doesn't have it as special case)
test_mv_mean_2samp

Stata has several null hypothesis in one sample case:

equal test that variables in varlist have equal means; the default
zero test that means of varlist are all equal to 0
equals(M) test that mean vector equals vector M
linear(V) test that mean vector of varlist satisfies linear hypothesis described by matrix V

aside: R package https://cran.r-project.org/web/packages/ICSNP/index.html
has rank based function
what about norm.ppf transform? (currently used as one of the cov estimators in robust PR)
Can we use marginal transformation?

(and then we get into copulas, ....)

@josef-pkt
josef-pkt force-pushed the multivariate_stats branch from 27d1f86 to 3c05be7 Compare May 6, 2020 18:54
@josef-pkt

Copy link
Copy Markdown
Member Author

I amended commit (only one so far) with pep-8 cleaning and removing __future__ import

@josef-pkt
josef-pkt force-pushed the multivariate_stats branch from 9f818bf to 40df01f Compare May 7, 2020 14:20
@josef-pkt

Copy link
Copy Markdown
Member Author

merge when green, extensions mv mean testing left for another time

@josef-pkt

Copy link
Copy Markdown
Member Author

lint check fails in statespace in master, not this PR

mergin

@josef-pkt
josef-pkt merged commit dc78a9d into statsmodels:master May 7, 2020
@bashtage bashtage modified the milestones: 0.10, 0.12 Jul 27, 2020
@josef-pkt
josef-pkt deleted the multivariate_stats branch February 21, 2021 02:54
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.

5 participants