Sum of squares type I, II, and III

TODO

  • link to anovaCRFpq, ancova, multMANOVA, multRegression

Install required packages

car

Background

Non-orthogonal factorial between-subjects designs typically result from non-proportional unequal cell sizes. Proportional unequal cell sizes are present when \(n_{jk}/n_{jk'} = n_{j'k}/n_{j'k'}\) and \(n_{jk}/n_{j'k} = n_{jk'}/n_{j'k'}\) for all \(j, j', k, k'\) holds.

In the non-proportional case, so-called type I, II, or III sums of squares can give different results in an ANOVA for all tests but the highest interaction effect. “Types of SS” is a misnomer: The SS of an effect is the sum of squared differences between the predicted values from the least-squares fit of a restricted model and the prediction from the least-squares fit of a more general model. What differs between the “types of SS” is the choice for the restricted and more general model when testing an effect. Orthogonal designs obscure these differences because then all SS types will be equal.

SAS and SPSS use SS type III as their default, while functions that ship with base R use type I. This can lead to different results when analyzing the same data with different statistics packages.

A thorough resource on the topic is chapter 7 of Maxwell & Delaney (2004). Designing Experiments and Analyzing Data. A Model Comparison Perspective. Mahwah, NJ: Lawrence Erlbaum. A formula for type III SS is derived in https://arxiv.org/pdf/1804.00545v1.pdf.

Hypotheses for main effects

Hypotheses for main effects as tested by different SS types in a non-proportional unbalanced two-factorial between-subjects design (IV A with \(P\) groups, B with \(Q\) groups).

  • Cell expected values
    • \(\mu_{jk} \quad 1 \leq j \leq P, \quad 1 \leq k \leq Q\)
  • Unweighted marginal expected values:
    • \(\mu_{j.} := \frac{1}{Q} \sum_{k=1}^{Q} \mu_{jk} \quad 1 \leq j \leq P\)
    • \(\mu_{.k} := \frac{1}{P} \sum_{j=1}^{P} \mu_{jk} \quad 1 \leq k \leq Q\)
  • Cell sizes
    • \(n_{jk} \quad 1 \leq j \leq P, \quad 1 \leq k \leq Q\)
  • Total marginal cell sizes
    • \(n_{j+} := \sum_{k=1}^{Q} n_{jk} \quad 1 \leq j \leq P\)
    • \(n_{+k} := \sum_{j=1}^{P} n_{jk} \quad 1 \leq k \leq Q\)

Null-Hypotheses SS type I (A entered before B):

A: \(\sum_{k=1}^{Q} \frac{n_{1k}}{n_{1+}} \cdot \mu_{1k} = \ldots = \sum_{k=1}^{Q} \frac{n_{jk}}{n_{j+}} \cdot \mu_{jk} = \ldots = \sum_{k=1}^{Q} \frac{n_{Pk}}{n_{P+}} \cdot \mu_{Pk}\)

B: \(\sum_{j=1}^{P}(n_{jk} - \frac{n^{2}_{jk}}{n_{j+}}) \cdot \mu_{jk} = \sum_{k' \neq k} \sum_{j=1}^{P}(\frac{n_{jk} \cdot n_{jk'}}{n_{j+}}) \cdot \mu_{jk'} \qquad \forall \, k = 1, \ldots, Q-1\)

Null-Hypotheses SS type II:

A: \(\sum_{k=1}^{Q}(n_{jk} - \frac{n^{2}_{jk}}{n_{+k}}) \cdot \mu_{jk} = \sum_{j' \neq j} \sum_{k=1}^{Q}(\frac{n_{jk} \cdot n_{j'k}}{n_{+k}}) \cdot \mu_{j'k} \qquad \forall \, j = 1, \ldots, P-1\)

B: \(\sum_{j=1}^{P}(n_{jk} - \frac{n^{2}_{jk}}{n_{j+}}) \cdot \mu_{jk} = \sum_{k' \neq k} \sum_{j=1}^{P}(\frac{n_{jk} \cdot n_{jk'}}{n_{j+}}) \cdot \mu_{jk'} \qquad \forall \,k = 1, \ldots, Q-1\)

Null-Hypotheses SS type III (with effect- or orthogonal coding method):

A: \(\mu_{1.} = \ldots = \mu_{j.} = \ldots = \mu_{P.}\) B: \(\mu_{.1} = \ldots = \mu_{.k} = \ldots = \mu_{.Q}\)

Data set with non-proportional unequal cell sizes

   IV2
IV1 1 2 3
  1 3 5 7
  2 5 6 4
  3 5 4 6

SS type I (sequential sum of squares)

Type I sum of squares have the following properties:

  • They use sequential model comparisons that conform to the principle of marginality (higher order terms are entered after all corresponding lower order terms).
  • Due to the sequential nature of the model comparisons, they depend on the order of model terms.
  • The individual effect SS sum to the total effect SS
  • They test for the equality of weighted marginal expected values (see above). -> the hypotheses take the empirical cell sizes into account
  • They do not depend on the contrast coding scheme used for categorical variables.

Factor order matters

Analysis of Variance Table

Response: DV
          Df  Sum Sq Mean Sq F value    Pr(>F)    
IV1        2  101.11   50.56  1.8102    0.1782    
IV2        2 1253.19  626.59 22.4357 4.711e-07 ***
IV1:IV2    4   14.19    3.55  0.1270    0.9717    
Residuals 36 1005.42   27.93                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analysis of Variance Table

Response: DV
          Df  Sum Sq Mean Sq F value    Pr(>F)    
IV2        2 1115.82  557.91 19.9764 1.458e-06 ***
IV1        2  238.48  119.24  4.2695   0.02168 *  
IV2:IV1    4   14.19    3.55  0.1270   0.97170    
Residuals 36 1005.42   27.93                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Sequential model comparisons

[1] 101.1111
[1] 1253.189
[1] 14.18714

Total SS \(=\) sum of effect SS

[1] 1368.487
[1] 1368.487

SS type II

Type II sum of squares have the following properties:

  • They test model comparisons that conform to the principle of marginality.
  • They do not depend on the order of model terms.
  • They test hypotheses about weighted cell expected values (see above). -> the hypotheses take the empirical cell sizes into account
  • The individual effect SS do not sum to the total effect SS.
  • The result does not depend on the coding scheme for categorical variables.

Using Anova() from package car

Anova Table (Type II tests)

Response: DV
           Sum Sq Df F value    Pr(>F)    
IV1        238.48  2  4.2695   0.02168 *  
IV2       1253.19  2 22.4357 4.711e-07 ***
IV1:IV2     14.19  4  0.1270   0.97170    
Residuals 1005.42 36                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Using model comparisons

[1] 238.4826
[1] 1253.189
[1] 14.18714

Total SS \(\neq\) sum of effect SS

[1] 1368.487
[1] 1505.859

SS type III

Type III sum of squares have the following properties:

  • They test model comparisons that violate the principle of marginality when testing main effects.
  • They do not depend on the order of model terms.
  • The individual effect SS do not sum to the total effect SS.
  • They test for the equality of unweighted marginal expected values (see above). -> the hypotheses do not take empirical cell sizes into account
  • These hypotheses are only tested when using effect- or orthogonal coding for categorical variables (e.g., Helmert).

Using Anova() from package car

Anova Table (Type III tests)

Response: DV
            Sum Sq Df   F value    Pr(>F)    
(Intercept) 121174  1 4338.7178 < 2.2e-16 ***
IV1            205  2    3.6658   0.03556 *  
IV2           1181  2   21.1452 8.447e-07 ***
IV1:IV2         14  4    0.1270   0.97170    
Residuals     1005 36                        
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Model comparisons using drop1()

The model comparisons for main effects with SS type III cannot be done using anova() due to the violation of marginality principle - anova() automatically includes all lower-order terms for the interactions it finds. This would be the comparison:

In contrast, drop1() drops each term in turn even if marginality is violated, so it gives SS type III.

Single term deletions

Model:
DV ~ IV1 + IV2 + IV1:IV2
        Df Sum of Sq    RSS    AIC F value    Pr(>F)    
<none>               1005.4 157.79                      
IV1      2    204.76 1210.2 162.13  3.6658   0.03556 *  
IV2      2   1181.11 2186.5 188.75 21.1452 8.447e-07 ***
IV1:IV2  4     14.19 1019.6 150.42  0.1270   0.97170    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Single term deletions

Model:
DV ~ IV1 + IV2 + IV1:IV2
        Df Sum of Sq    RSS    AIC F value    Pr(>F)    
<none>               1005.4 157.79                      
IV1      2    204.76 1210.2 162.13  3.6658   0.03556 *  
IV2      2   1181.11 2186.5 188.75 21.1452 8.447e-07 ***
IV1:IV2  4     14.19 1019.6 150.42  0.1270   0.97170    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Detach (automatically) loaded packages (if possible)

Get the article source from GitHub

R markdown - markdown - R code - all posts