statsmodels / statsmodels

Statsmodels: statistical modeling and econometrics in Python
http://www.statsmodels.org/devel/
BSD 3-Clause "New" or "Revised" License
10.21k stars 3.04k forks source link

Repeated measure ANOVA with Greenhouse-Geisser Correction #9274

Open anantawasthi opened 5 months ago

anantawasthi commented 5 months ago

Describe the bug

I am not able to run repeated measure ANOVA with Greenhouse-Geisser Correction.

Code Sample, a copy-pastable example if possible

        from statsmodels.stats.anova import AnovaRM        
        corrected_r_measure_anova = AnovaRM(bpdata, 'Score', 'Athelete', within=['Test_State'], correction='GG')
**Note**: As you can see, there are many issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates. **Note**: Please be sure you are using the latest released version of `statsmodels`, or a recent build of `main`. If your problem has been fixed in an unreleased version, you might be able to use `main` until a new release occurs. **Note**: If you are using a released version, have you verified that the bug exists in the main branch of this repository? It helps the limited resources if we know problems exist in the current main branch so that they do not need to check whether the code sample produces a bug in the next release.

If the issue has not been resolved, please file it in the issue tracker.

Expected Output

A Standard Output of AnovaRM

Error

image

Output of import statsmodels.api as sm; sm.show_versions()

[paste the output of ``import statsmodels.api as sm; sm.show_versions()`` here below this line] INSTALLED VERSIONS ------------------ Python: 3.11.9.final.0 statsmodels =========== Installed: 0.14.0 (c:\Users\Anant\anaconda3\Lib\site-packages\statsmodels) Required Dependencies ===================== cython: Not installed numpy: 1.24.3 (c:\Users\Anant\anaconda3\Lib\site-packages\numpy) scipy: 1.10.1 (c:\Users\Anant\anaconda3\Lib\site-packages\scipy) pandas: 2.2.1 (c:\Users\Anant\anaconda3\Lib\site-packages\pandas) dateutil: 2.9.0.post0 (c:\Users\Anant\anaconda3\Lib\site-packages\dateutil) patsy: 0.5.3 (c:\Users\Anant\anaconda3\Lib\site-packages\patsy) Optional Dependencies ===================== matplotlib: 3.8.4 (c:\Users\Anant\anaconda3\Lib\site-packages\matplotlib) backend: module://matplotlib_inline.backend_inline cvxopt: Not installed joblib: 1.4.0 (c:\Users\Anant\anaconda3\Lib\site-packages\joblib) Developer Tools ================ IPython: 8.20.0 (c:\Users\Anant\anaconda3\Lib\site-packages\IPython) jinja2: 3.1.4 (c:\Users\Anant\anaconda3\Lib\site-packages\jinja2) sphinx: 5.0.2 (c:\Users\Anant\anaconda3\Lib\site-packages\sphinx) pygments: 2.15.1 (c:\Users\Anant\anaconda3\Lib\site-packages\pygments) pytest: 7.4.4 (c:\Users\Anant\anaconda3\Lib\site-packages\pytest) virtualenv: Not installed
YongcaiHuang commented 5 months ago

Upvote. Currently, AnovaRM is somehow limited with no support of spherity GG-corr and the between factor. It would be great if any plan to support this!

josef-pkt commented 5 months ago

AFAIR, I never looked at this, and I don't know how difficult it is to add.

a recent article with Monte Carlo comparison of test size:

Blanca MJ, Arnau J, García-Castro FJ, Alarcón R, Bono R. Repeated measures ANOVA and adjusted F-tests when sphericity is violated: which procedure is best? Front Psychol. 2023 Aug 30;14:1192453. doi: 10.3389/fpsyg.2023.1192453. PMID: 37711324; PMCID: PMC10499170. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10499170/ uncorrected F-test vastly over-rejects in their table 1 (based on very brief skimming of article)

laerd has an intro https://statistics.laerd.com/statistical-guides/sphericity-statistical-guide-2.php which refers to SPSS, which usually has a good formula collection in the docs.

degrees of freedom correction in the style of robust cov_type. (AFAIR from some simulated experiments I did, cluster robust cov_type requires large number of clusters which is not required in RM-Anova) Worth a look to see if it is easy enough to implement so we can still add it for 0.15.