I am trying to run a multivariate regression model using statsmodels, but there appears to be no implementation of that yet, so in the meantime, what I did was to run a manova model on the data like below:
# the modules
import pandas as pd
from statsmodels.multivariate.manova import MANOVA
from statsmodels.multivariate.multivariate_ols import _MultivariateOLS
from statsmodels.multivariate.multivariate_ols import MultivariateTestResults
# manova
mod = MANOVA.from_formula('se + em ~ pv + ed + fs + hp', df)
mod_mvtest = mod.mv_test()
mod_mvtest.summary_frame
# the output
pd.DataFrame({'Value': {('Intercept', "Wilks' lambda"): 0.35959042974944566,
('Intercept', "Pillai's trace"): 0.6404095702505543,
('Intercept', 'Hotelling-Lawley trace'): 1.780941641569207,
('Intercept', "Roy's greatest root"): 1.780941641569207,
('pv', "Wilks' lambda"): 0.9995874157798398,
('pv', "Pillai's trace"): 0.00041258422016027143,
('pv', 'Hotelling-Lawley trace'): 0.0004127545161604391,
('pv', "Roy's greatest root"): 0.0004127545161604391,
('ed', "Wilks' lambda"): 0.9947762433747658,
('ed', "Pillai's trace"): 0.005223756625234229,
('ed', 'Hotelling-Lawley trace'): 0.005251187550994082,
('ed', "Roy's greatest root"): 0.005251187550994082,
('fs', "Wilks' lambda"): 0.9906903180436285,
('fs', "Pillai's trace"): 0.009309681956371496,
('fs', 'Hotelling-Lawley trace'): 0.009397166588602426,
('fs', "Roy's greatest root"): 0.009397166588602426,
('hp', "Wilks' lambda"): 0.9643721311041931,
('hp', "Pillai's trace"): 0.035627868895806984,
('hp', 'Hotelling-Lawley trace'): 0.036944108759150426,
('hp', "Roy's greatest root"): 0.036944108759150426},
'Num DF': {('Intercept', "Wilks' lambda"): 2,
('Intercept', "Pillai's trace"): 2.0,
('Intercept', 'Hotelling-Lawley trace'): 2,
('Intercept', "Roy's greatest root"): 2,
('pv', "Wilks' lambda"): 2,
('pv', "Pillai's trace"): 2.0,
('pv', 'Hotelling-Lawley trace'): 2,
('pv', "Roy's greatest root"): 2,
('ed', "Wilks' lambda"): 2,
('ed', "Pillai's trace"): 2.0,
('ed', 'Hotelling-Lawley trace'): 2,
('ed', "Roy's greatest root"): 2,
('fs', "Wilks' lambda"): 2,
('fs', "Pillai's trace"): 2.0,
('fs', 'Hotelling-Lawley trace'): 2,
('fs', "Roy's greatest root"): 2,
('hp', "Wilks' lambda"): 2,
('hp', "Pillai's trace"): 2.0,
('hp', 'Hotelling-Lawley trace'): 2,
('hp', "Roy's greatest root"): 2},
'Den DF': {('Intercept', "Wilks' lambda"): 11608.0,
('Intercept', "Pillai's trace"): 11608.0,
('Intercept', 'Hotelling-Lawley trace'): 11608.000000002476,
('Intercept', "Roy's greatest root"): 11608,
('pv', "Wilks' lambda"): 11608.0,
('pv', "Pillai's trace"): 11608.0,
('pv', 'Hotelling-Lawley trace'): 11608.000000002476,
('pv', "Roy's greatest root"): 11608,
('ed', "Wilks' lambda"): 11608.0,
('ed', "Pillai's trace"): 11608.0,
('ed', 'Hotelling-Lawley trace'): 11608.000000002476,
('ed', "Roy's greatest root"): 11608,
('fs', "Wilks' lambda"): 11608.0,
('fs', "Pillai's trace"): 11608.0,
('fs', 'Hotelling-Lawley trace'): 11608.000000002476,
('fs', "Roy's greatest root"): 11608,
('hp', "Wilks' lambda"): 11608.0,
('hp', "Pillai's trace"): 11608.0,
('hp', 'Hotelling-Lawley trace'): 11608.000000002476,
('hp', "Roy's greatest root"): 11608},
'F Value': {('Intercept', "Wilks' lambda"): 10336.585287667678,
('Intercept', "Pillai's trace"): 10336.585287667676,
('Intercept', 'Hotelling-Lawley trace'): 10336.585287667674,
('Intercept', "Roy's greatest root"): 10336.585287667678,
('pv', "Wilks' lambda"): 2.3956272117948725,
('pv', "Pillai's trace"): 2.3956272117951882,
('pv', 'Hotelling-Lawley trace'): 2.3956272117951882,
('pv', "Roy's greatest root"): 2.3956272117951882,
('ed', "Wilks' lambda"): 30.477892545969606,
('ed', "Pillai's trace"): 30.477892545969652,
('ed', 'Hotelling-Lawley trace'): 30.477892545969645,
('ed', "Roy's greatest root"): 30.477892545969652,
('fs', "Wilks' lambda"): 54.54115488024848,
('fs', "Pillai's trace"): 54.54115488024848,
('fs', 'Hotelling-Lawley trace'): 54.54115488024847,
('fs', "Roy's greatest root"): 54.54115488024848,
('hp', "Wilks' lambda"): 214.4236072381088,
('hp', "Pillai's trace"): 214.4236072381091,
('hp', 'Hotelling-Lawley trace'): 214.42360723810904,
('hp', "Roy's greatest root"): 214.42360723810907},
'Pr > F': {('Intercept', "Wilks' lambda"): 0.0,
('Intercept', "Pillai's trace"): 0.0,
('Intercept', 'Hotelling-Lawley trace'): 0.0,
('Intercept', "Roy's greatest root"): 0.0,
('pv', "Wilks' lambda"): 0.09116055879307752,
('pv', "Pillai's trace"): 0.09116055879307752,
('pv', 'Hotelling-Lawley trace'): 0.09116055879303571,
('pv', "Roy's greatest root"): 0.09116055879307752,
('ed', "Wilks' lambda"): 6.284223443412654e-14,
('ed', "Pillai's trace"): 6.284223443412654e-14,
('ed', 'Hotelling-Lawley trace'): 6.284223443411805e-14,
('ed', "Roy's greatest root"): 6.284223443412654e-14,
('fs', "Wilks' lambda"): 2.652650399331105e-24,
('fs', "Pillai's trace"): 2.652650399331105e-24,
('fs', 'Hotelling-Lawley trace'): 2.6526503993306902e-24,
('fs', "Roy's greatest root"): 2.652650399331105e-24,
('hp', "Wilks' lambda"): 3.5971364993426025e-92,
('hp', "Pillai's trace"): 3.5971364993426025e-92,
('hp', 'Hotelling-Lawley trace'): 3.5971364993389216e-92,
('hp', "Roy's greatest root"): 3.5971364993426025e-92}})
I know that the multivariate omnibus test gives me some ideas about the associations between the predictors and the responses. What I want to do next is some linear hypothesis testing, but can't seem to figure that out in statsmodels. I can't seem to find any documentation with pointers.
For example, what I would like to do is to compare whether the effects of the predictors are the same across both responses. In R, using the car package linearhypothesis()
function, I could do something like this:
rhs = matrix(c(1, -1), ncol=2)
linearHypothesis(model=mod, hypothesis.matrix="pv", rhs=rhs,
title = "equality of cofficients for pv predictor",
verbose=TRUE)
#where the rhs = matrix [1, -1] describes the coefficient difference I am testing for, while the
#hypothesis.matrix='pv' restricts the coefficient difference I am testing to the pv predictor only.