You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FAQ/ENH: Discrepencies in two-way MANOVA between statsmodels and SPSS #6464
Results differ depending on which factor I place first in the model. This is true also when I write the full formula (type_home_collection + type_kerbside_collection + type_staffed_dop ~ C(PROD_TYPE) + C(GEND) + C(PROD_TYPE):C(GEND) -1)
Results are different from what I get in SPSS: the interaction effect is similar, but main effects are not
I checked and my input data is exactly the same in both cases (I actually exported my DataFrame from python).
Unfortunately I'm neither good enough in statistics nor in programming to solve that, but I hope this may help...
Thanks for reporting. This is not enough information. I don't have SPSS and cannot check this.
Did you try the same with the constant, no -1 in the formula?
My guess is that there might be different encodings between statsmodels/patsy and SPSS, so that we are actually test different hypothesis.
AFAIR, the hypothesis test are constructed on the parameters, and with different encodings the null hypothesis will differ unless they are transformed to encoding independent constrast matrices.
The other possibility is that we define things differently from SPSS for non-orthogonal two way designs. (I don't know what SPSS does,)
The best would be if you can come up with a replicable example and the expected output from SPSS.
Otherwise, you can add the output from spss and statsmodels to this issue, and we see if we have a guess based on it.
I'm not very familiar with our MANOVA and will need to look at it again. I never went through the details of the formula handling in it.
(The original author of our MANOVA is not active in statsmodels anymore.)
we don't have unit tests for 2-way MANOVA (test_manova.py)
the underlying code with mv_test has at least one two-way unit test in test_multivariate_ols.py
So, my guess is that the underlying mv_test method is fine, but MANOVA constructs different contrast matrices depending on the encoding of the two-way factors in exog.
@JMansuy Does SPSS show which contrast matrices they use for the different hypothesis?
AFAICS from the SPSS computation, they do a reparameterization to cell means in the MANOVA case, and something similar in the MANCOVA case.
The details in the SPSS algorithm docs are not very clear to me. It looks like a traditional ANOVA style analysis and not going through the linear model directly. There might be problems with non-orthogonal designs in the SPSS case, i.e. incomplete block design.
edit it looks like WLS on cell means with W = "D is the diagonal matrix of cell frequencies".
They also (optionally) incorporate the contrasts L in the reparameterization before estimation.
Then they mention just simple unit tests like H0 : theta_h = 0.
We and AFAIR, SAS compute parameters B from the original parameterization and then test hypothesis L * params * M = C in mv_test
@JMansuy Can you compare a cell parameterization to SPSS?
formula 'type_home_collection + type_kerbside_collection + type_staffed_dop ~ C(PROD_TYPE) : C(GEND) -1'
Please find below the answers to your suggestions. Unfortunately I'm not very familiar with MANOVA nor python (I learned both for my paper), and even less with SPSS, so apologies in advance if my feedback is not very helpful.
On the MANOVA above, here is what Statsmodels and SPSS send me:
Statsmodel:
SPSS:
I did some tests with other factors and it looks like Statsmodels and SPSS are giving the same F Values (and p-values) for the interaction effect.
Removing the constant does not change neither the F Value nor the the p-value.
I'm not familiar with the contrast concept yet, so do not hesitate to ask me for further precisions if I do not explain well on this part. In SPSS the constrast is set to "None" for both variables, but you can select several other options (deviation, simple, difference, Helmert, repeated and polynomial) for each variable separately. I've also read about a multivariate contrast which is kind of "hidden". I do not think I have access to the contrast matrix in use.
When doing the cell parametrization I have that:
Hope this helps a bit...
Do not hesitate to tell me if you want me to perform other tasks.
One more check: leave out the interaction effect in the statmodels version, and see what results you get.
In standard anova tables, R, leaves out the interaction effect when evaluating the main effect, while we don't do that. Maybe they do something similar in MANOVA.
Please add your commands and package for the R results in your last comment. If R agrees with SPSS in this case, then it will be easier to investigate.
Aside: Yesterday I was reading or skimming articles from the 1970s in the psychology literature about using linear models instead of anova for unbalanced design and they argued for a while which type of anova to use (1, 2 or 3). The types all agree for a balanced design but differ for unbalanced (different cell frequency) designs.
In my case I have an unbalanced design, and I've indeed seen the difference using type I, II or III with the anova_lm method for my dependent variables separately.
Did you include the constant in the no-interaction effect model in your previous to last comment?
degrees of freedom Den DF difference is pretty large, but also the Num DF in C(PROD_TYPE)
It looks like SPSS and R have the same DF2/Den DF for prod_type main effect as for for the interaction. That might mean that they are still using information from the full model, when computing the main effect.
FYI, I removed the intersect also in the SPSS model I posted, but it did not change the results.
The SPSS output with interesect:
The difference in Den DF is surprising indeed, I have no idea either. I'll continue learning about MANOVA, and I'll keep you updated if I find an idea on that.
So, I guess SPSS is doing something slightly different than SAS. I don't think that's specific to two-way effects.
(I never tried to understand how df are justified in this case, this uses F distribution and not asymptotic chi2.)
SPSS has slightly smaller df_denom, which means we have slightly small pvalues and slightly larger rejection rates.
We have fractional df_denm in Hotelling-Lawley trace, so my SAS and our df are better. (?)
@JMansuy One more to compare to SPSS.
Can you get the results for a one-way MANOVA, i.e. use only one of the main effects?
changed the title [-]Discrepencies in two-way MANOVA between statsmodels and SPSS[/-][+]FAQ/ENH: Discrepencies in two-way MANOVA between statsmodels and SPSS[/+]on Jan 24, 2020
According to the SPSS manova docs (in IBM_SPSS_Statistics_Command_Syntax_Reference.pdf) there is a METHOD=UNIQUE option that sounds like type 3 ANOVA, but AFAIU it is the default.
Can you check whether adding this option makes a difference in the SPSS two-way manova?
Otherwise, AFAICS, there is only the difference in degrees of freedom, especially Hotelling's trace
We can indeed change the method in SPSS. Here is what happens when I select type 2 (METHOD=SSTYPE(2)):
And here is the table with type 3 selected (METHOD=SSTYPE(3)):
We can also select type 1 and type 4. Not sure which one applies best to my case (I randomly assigned PROD_TYPE to my respondents), but all the previously sent tables are made with a type 2 model.
with the intercept we have now the same DF in statsmodels as in SPSS.
The actual test statistics for the main effects don't agree with SPSS type 3 either. So no idea how what those tests condition on.
(I'm not completely sure our manova does pure type 3 in the sense of testing the main effect only even when an interaction effect is in the model.)
The interaction effect results (f-value, p-value agrees even though our reported Den DF is different.
Activity
josef-pkt commentedon Jan 24, 2020
Thanks for reporting. This is not enough information. I don't have SPSS and cannot check this.
Did you try the same with the constant, no
-1in the formula?My guess is that there might be different encodings between statsmodels/patsy and SPSS, so that we are actually test different hypothesis.
AFAIR, the hypothesis test are constructed on the parameters, and with different encodings the null hypothesis will differ unless they are transformed to encoding independent constrast matrices.
The other possibility is that we define things differently from SPSS for non-orthogonal two way designs. (I don't know what SPSS does,)
The best would be if you can come up with a replicable example and the expected output from SPSS.
Otherwise, you can add the output from spss and statsmodels to this issue, and we see if we have a guess based on it.
I'm not very familiar with our MANOVA and will need to look at it again. I never went through the details of the formula handling in it.
(The original author of our MANOVA is not active in statsmodels anymore.)
josef-pkt commentedon Jan 24, 2020
unit tests: AFAICS,
test_manova.py)mv_testhas at least one two-way unit test intest_multivariate_ols.pySo, my guess is that the underlying
mv_testmethod is fine, but MANOVA constructs different contrast matrices depending on the encoding of the two-way factors in exog.@JMansuy Does SPSS show which contrast matrices they use for the different hypothesis?
josef-pkt commentedon Jan 24, 2020
AFAICS from the SPSS computation, they do a reparameterization to cell means in the MANOVA case, and something similar in the MANCOVA case.
The details in the SPSS
algorithmdocs are not very clear to me. It looks like a traditional ANOVA style analysis and not going through the linear model directly. There might be problems with non-orthogonal designs in the SPSS case, i.e. incomplete block design.edit it looks like WLS on cell means with W = "D is the diagonal matrix of cell frequencies".
They also (optionally) incorporate the contrasts
Lin the reparameterization before estimation.Then they mention just simple unit tests like H0 : theta_h = 0.
We and AFAIR, SAS compute parameters
Bfrom the original parameterization and then test hypothesisL * params * M = Cinmv_test@JMansuy Can you compare a cell parameterization to SPSS?
formula
'type_home_collection + type_kerbside_collection + type_staffed_dop ~ C(PROD_TYPE) : C(GEND) -1'josef-pkt commentedon Jan 24, 2020
AFAIR, and based on unit tests, we were using SAS docs when MANCOVA was added.
JMansuy commentedon Jan 24, 2020
Hello Josef, thanks for your answer!
Please find below the answers to your suggestions. Unfortunately I'm not very familiar with MANOVA nor python (I learned both for my paper), and even less with SPSS, so apologies in advance if my feedback is not very helpful.
On the MANOVA above, here is what Statsmodels and SPSS send me:
Statsmodel:

SPSS:

I did some tests with other factors and it looks like Statsmodels and SPSS are giving the same F Values (and p-values) for the interaction effect.
Removing the constant does not change neither the F Value nor the the p-value.
I'm not familiar with the contrast concept yet, so do not hesitate to ask me for further precisions if I do not explain well on this part. In SPSS the constrast is set to "None" for both variables, but you can select several other options (deviation, simple, difference, Helmert, repeated and polynomial) for each variable separately. I've also read about a multivariate contrast which is kind of "hidden". I do not think I have access to the contrast matrix in use.
When doing the cell parametrization I have that:

Hope this helps a bit...
Do not hesitate to tell me if you want me to perform other tasks.
JMansuy commentedon Jan 24, 2020
FYI I got the same results in Jamovi (coded in R) as compared to SPSS:

josef-pkt commentedon Jan 24, 2020
One more check: leave out the interaction effect in the statmodels version, and see what results you get.
In standard anova tables, R, leaves out the interaction effect when evaluating the main effect, while we don't do that. Maybe they do something similar in MANOVA.
Please add your commands and package for the R results in your last comment. If R agrees with SPSS in this case, then it will be easier to investigate.
josef-pkt commentedon Jan 24, 2020
Aside: Yesterday I was reading or skimming articles from the 1970s in the psychology literature about using linear models instead of anova for unbalanced design and they argued for a while which type of anova to use (1, 2 or 3). The types all agree for a balanced design but differ for unbalanced (different cell frequency) designs.
JMansuy commentedon Jan 24, 2020
When I leave out the interaction effect, I get the same (more or less) main effects as in SPSS indeed:

Regarding R, the package is jmv (their GitHub: https://github.com/jamovi/jamovi)
JMansuy commentedon Jan 24, 2020
In my case I have an unbalanced design, and I've indeed seen the difference using type I, II or III with the anova_lm method for my dependent variables separately.
josef-pkt commentedon Jan 24, 2020
Did you include the constant in the no-interaction effect model in your previous to last comment?
degrees of freedom Den DF difference is pretty large, but also the Num DF in
C(PROD_TYPE)It looks like SPSS and R have the same DF2/Den DF for prod_type main effect as for for the interaction. That might mean that they are still using information from the full model, when computing the main effect.
JMansuy commentedon Jan 24, 2020
No indeed, I did not include the constant. Here are the results with the intercept:
josef-pkt commentedon Jan 24, 2020
Good, that's getting close.
Now
Den DFdiffers by just around2or 2 to 4I have no guess where that might come from.
JMansuy commentedon Jan 24, 2020
FYI, I removed the intersect also in the SPSS model I posted, but it did not change the results.
The SPSS output with interesect:

The difference in Den DF is surprising indeed, I have no idea either. I'll continue learning about MANOVA, and I'll keep you updated if I find an idea on that.
Thanks for the support on this issue!
josef-pkt commentedon Jan 24, 2020
our implementation refers to SAS docs for details for the mv_test statistics and df
https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_introreg_sect012.htm
So, I guess SPSS is doing something slightly different than SAS. I don't think that's specific to two-way effects.
(I never tried to understand how df are justified in this case, this uses F distribution and not asymptotic chi2.)
SPSS has slightly smaller df_denom, which means we have slightly small pvalues and slightly larger rejection rates.
We have fractional df_denm in Hotelling-Lawley trace, so my SAS and our df are better. (?)
@JMansuy One more to compare to SPSS.
Can you get the results for a one-way MANOVA, i.e. use only one of the main effects?
[-]Discrepencies in two-way MANOVA between statsmodels and SPSS[/-][+]FAQ/ENH: Discrepencies in two-way MANOVA between statsmodels and SPSS[/+]JMansuy commentedon Jan 25, 2020
Sure, here is the output for one-way MANOVA for SPSS:

And here for Statsmodels:

josef-pkt commentedon Jan 25, 2020
I found one more thing to check:
According to the SPSS manova docs (in IBM_SPSS_Statistics_Command_Syntax_Reference.pdf) there is a
METHOD=UNIQUEoption that sounds like type 3 ANOVA, but AFAIU it is the default.Can you check whether adding this option makes a difference in the SPSS two-way manova?
Otherwise, AFAICS, there is only the difference in degrees of freedom, especially Hotelling's trace
JMansuy commentedon Jan 25, 2020
We can indeed change the method in SPSS. Here is what happens when I select type 2 (METHOD=SSTYPE(2)):

And here is the table with type 3 selected (METHOD=SSTYPE(3)):

We can also select type 1 and type 4. Not sure which one applies best to my case (I randomly assigned PROD_TYPE to my respondents), but all the previously sent tables are made with a type 2 model.
josef-pkt commentedon Jan 25, 2020
@JMansuy one last one, then I think we have all main comparisons between SPSS and statsmodels.
show the results of your original two-way interaction model in statsmodels but with a constant included (no
-1)Then we have the direct comparison to the different types of SPSS manovas
JMansuy commentedon Jan 25, 2020
Sure, here it is:

josef-pkt commentedon Jan 25, 2020
with the intercept we have now the same DF in statsmodels as in SPSS.
The actual test statistics for the main effects don't agree with SPSS type 3 either. So no idea how what those tests condition on.
(I'm not completely sure our manova does pure type 3 in the sense of testing the main effect only even when an interaction effect is in the model.)
The interaction effect results (f-value, p-value agrees even though our reported Den DF is different.