Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MANOVA using stats models

I'm looking for an example of a statsmodels MANOVA implementation. I can't make heads or tails of the Statsmodels website for MANOVA. I've gotten as far as:

endog, exog = np.asarray(pre_post[feats_list]), np.asarray(pre_post[features])
man = sm.MANOVA(endog,exog).fit()

But with .fit() I get an error:

NotImplementedError: 

If I put any kind of input into .fit(), it tells me there are too many arguments.

TypeError: fit() takes 1 positional argument but 2 were given

I did read this post and managed to replicate the same error with

man = sm.MANOVA(endog,exog)
man.mv_test()

But it doesn't seem like there was ever a resolution there either.

I know it's kind of basic in terms of a programming question, but I would be indebted to anyone who can provide any insight on how to get MANOVA working and how to get the results out of the model after its been fit. It doesn't seem to be a popular package in Python and I can't find any examples online. Many thanks.

like image 718
Alicia Avatar asked Oct 27 '25 08:10

Alicia


1 Answers

Here's a small example that shows how to use the function:

import numpy as np
from statsmodels.multivariate.manova import MANOVA

n_samples = 20
n_dim = 5
n_classes = 3

X = np.random.randn(n_samples, n_dim)
y = np.random.randint(n_classes, size=n_samples)

manova = MANOVA(endog=X, exog=y)
print(manova.mv_test())

which outputs

                 Multivariate linear model
============================================================

------------------------------------------------------------
           x0           Value  Num DF  Den DF F Value Pr > F
------------------------------------------------------------
          Wilks' lambda 0.3681 4.0000 16.0000  6.8678 0.0020
         Pillai's trace 0.6319 4.0000 16.0000  6.8678 0.0020
 Hotelling-Lawley trace 1.7170 4.0000 16.0000  6.8678 0.0020
    Roy's greatest root 1.7170 4.0000 16.0000  6.8678 0.0020
============================================================

For an example that shows how to use the from_formula interface, see this blog post.

like image 148
Vivek Avatar answered Oct 29 '25 23:10

Vivek