The default output for the ANOVA function is that of a type 1 Sum of Squares (SS) table. This is sufficient for a one-way ANOVA, however, when running an n-way ANOVA (with n greater than 1) and allowing for interactions to be tested the "accepted" method seems to be either type 2 or 3 SS. I have been unable to locate a method allowing the output of the type 3 SS from the ANOVA function and have confirmed using XLSTAT that the output from the ANOVA function in Mathematica is a type 1 SS. I can of course make use of XLSTAT for such analyses but would like to use Mathematica for all data analysis if possible. Below is an example to showcase the effect of factor order on the type 1 SS for unbalanced data. The dataset shown below is copied from the ANOVA documentation page with the last entry removed to make the dataset unbalanced.
threewaydata = {{1, 1, 1, 50}, {1, 1, 1, 50}, {1, 1, 1, 54}, {1, 1, 2,
40}, {1, 1, 2, 36}, {1, 1, 2, 40}, {1, 2, 1, 48}, {1, 2, 1,
48}, {1, 2, 1, 44}, {1, 2, 2, 14}, {1, 2, 2, 18}, {1, 2, 2,
14}, {2, 1, 1, 40}, {2, 1, 1, 36}, {2, 1, 1, 36}, {2, 1, 2,
18}, {2, 1, 2, 14}, {2, 1, 2, 18}, {2, 2, 1, 6}, {2, 2, 1, 2}, {2,
2, 1, 2}, {2, 2, 2, 20}, {2, 2, 2, 16}};
The following code reorders the factors provided to the ANOVA function.
ANOVA[threewaydata[[All, {1, 2, 3, 4}]], {α, β, γ, All}, {α, β, γ}][[1]]
ANOVA[threewaydata[[All, {2, 1, 3, 4}]], {β, α, γ, All}, {β, α, γ}][[1]]
ANOVA[threewaydata[[All, {3, 1, 2, 4}]], {γ, α, β, All}, {γ, α, β}][[1]]
Below are the respective outputs. The p values for the factors and their interactions differ due to the order in which they are included (with the exception of the 3 way interaction as it is included last). This is not an issue when using a type 3 SS. For this reason I would like to know if the type 3 SS can be obtained either using the ANOVA function itself, or if there is another function capable of doing so.
The type 3 SS obtained from XLSTAT is shown below (this is the desired output). Below is the same analysis performed in Graphpad Prism. It appears to be an equivalent result to that of XLSTAT (with the factors in a different order and with less precision shown for the p-values)
FittedModel
(produced byLinearModelFit
) have a property called"SequentialSumOfSquares"
, and"PartialSumOfSquares"
which is what you're looking for (based on my limited knowledge, it doesn't supportAll
, and other statistics should be calculated manually). $\endgroup$LinearModelFit
gives an option for obtainingPartialSumOfSquares
which is what Type III SS are sometimes called. However, this doesn't match what SAS gives for Type III SS. $\endgroup$