0

I am trying to extract the within-group variance-covariance matrix to estimate the flatness in a MANOVA model in statsmodels using the following formula: flatness

I've been reading through the statsmodels user guide, but haven't come across it. What I have managed so far is this:

resid = manova.mv_test().results['x1']['E']
n * (xbar_tot).T @ np.linalg.solve(?, resid) @ xbar_tot

In R, the same can be accomplished by calling:

n * t(xbar.tot) %*% solve(summary(mod, test="Wilks")$SS$Residuals) %*% xbar.tot

What I am missing is the first part of the inverse, the where I have the ? in the code.

GSA
  • 751
  • 8
  • 12

1 Answers1

0

It turns out that the solution is simply the E matrix: so for the statsmodels manova question I asked, one proceeds as follows::

#1. run the statsmodel manova model
manova = MANOVA.from_formula('dv1 + dv2 ~ y', data=dy)

#2. extract the E matrix from the mv_test().results
resid = manova.mv_test().results['y']['E']

#3. obtain Hotelling's T^2
n * (xbar_tot).T @ np.linalg.solve(resid) @ xbar_tot
GSA
  • 751
  • 8
  • 12
  • Is there a typo in the last line of the code? np.linalg.solve requires 2 arguments – Josef Aug 27 '22 at 20:39
  • Yes, there is a typo (thanks for catching it). It's supposed to be `linalg.inv`, not `linalg.solve`. So the full code should read ```#1. run the statsmodel manova model manova = MANOVA.from_formula('dv1 + dv2 ~ y', data=dy) #2. extract the E matrix from the mv_test().results resid = manova.mv_test().results['y']['E'] #3. obtain Hotelling's T^2 n * (xbar_tot).T @ np.linalg.inv(resid) @ xbar_tot``` – GSA Aug 28 '22 at 16:48