class: center middle main-title section-title-1 # Complete factorial designs .class-info[ **Session 5** .light[MATH 80667A: Experimental Design and Statistical Methods <br>for Quantitative Research in Management <br> HEC Montréal ] ] --- name: outline class: title title-inv-1 # Outline .box-4.medium.sp-after-half[Factorial designs and interactions] .box-5.medium.sp-after-half[Model formulation] --- layout: false name: factorial-interaction class: center middle section-title section-title-4 animated fadeIn # Factorial designs and interactions --- layout: true class: title title-4 --- # Complete factorial designs? .box-inv-4.sp-after[ .large[**Factorial design**]<br> study with multiple factors (subgroups) ] .box-inv-4[.large[**Complete**] <br>Gather observations for every subgroup] --- # Motivating example .box-inv-4[**Response**:<br> retention of information <br>two hours after reading a story] .box-inv-4[**Population**:<br> children aged four] .box-inv-4.align-left[**experimental factor 1**:<br> ending (happy or sad)] .box-inv-4[**experimental factor 2**:<br> complexity (easy, average or hard).] --- # Setup of design
complexity
happy
sad
complicated
average
easy
.box-inv-4[Factors are crossed] --- # Efficiency of factorial design .box-inv-4.sp-after.medium[Cast problem<br>as a series of one-way ANOVA <br> vs simultaneous estimation] .box-4.medium.sp-before[Factorial designs requires<br> **fewer overall observations**] .box-4.medium.sp-before[Can study **interactions**] ??? To study each interaction (complexity, story book ending) we would need to make three group for each comparison in rows, and one in each column. So a total of 3 one-way ANOVA each with 2 groups and 2 one-way anova with 3 groups. The two-way ANOVA will lead to 6 groups instead of 12. --- # Interaction .box-inv-4.sp-after.medium[ **Definition**: when the effect of one factor<br> depends on the levels of another factor. ] .box-inv-4[ Effect together<br> `\(\neq\)` <br> sum of individual effects ] --- # Interaction or profile plot .box-inv-4.large.sp-after[Graphical display: <br>plot sample mean per category] .box-4.sp-after-half[with uncertainty measure<br>(1 std. error for mean<br>confidence interval, etc.)] --- # Interaction: lines are not parallel <img src="05-slides_files/figure-html/interaction_plots2-1.png" width="80%" style="display: block; margin: auto;" /> --- # No interaction: parallel lines <img src="05-slides_files/figure-html/interaction_plots1-1.png" width="80%" style="display: block; margin: auto;" /> --- # Interaction plot for 2 by 2 design <img src="05-slides_files/figure-html/2by2-interaction-1.png" width="70%" style="display: block; margin: auto;" /> ??? Line graph for example patterns for means for each of the possible kinds of general outcomes in a 2 by 2 design. Illustration adapted from Figure 10.2 of Crump, Navarro and Suzuki (2019) by Matthew Crump (CC BY-SA 4.0 license) --- layout: false name: formulation class: center middle section-title section-title-5 animated fadeIn # Model formulation --- layout: true class: title title-5 --- # Formulation of the two-way ANOVA Two factors: `\(A\)` (complexity) and `\(B\)` (ending) with `\(n_a\)` and `\(n_b\)` levels. Write the average response `\(Y_{ijr}\)` of the `\(r\)`th measurement in group `\((a_i, b_j)\)` as `\begin{align*} \underset{\text{response}\vphantom{b}}{Y_{ijr}} = \underset{\text{subgroup mean}}{\mu_{ij}} + \underset{\text{error term}}{\varepsilon_{ijr}} \end{align*}` where - `\(Y_{ijr}\)` is the `\(r\)`th replicate for `\(i\)`th level of factor `\(A\)` and `\(j\)`th level of factor `\(B\)` - `\(\varepsilon_{ijr}\)` are independent error terms with mean zero and variance `\(\sigma^2\)`. --- # One average for each subgroup | `\(\qquad B\)` `ending`<br> `\(A\)` `complexity` `\(\qquad\)` | `\(b_1\)` (`happy`) | `\(b_2\)` (`sad`)| *row mean* | |------------|:----------:|:-----:|:-----:| | `\(a_1\)` (`complicated`) | `\(\mu_{11}\)` | `\(\mu_{12}\)` | `\(\mu_{1.}\)` | | `\(a_2\)` (`average`) | `\(\mu_{21}\)` | `\(\mu_{22}\)` | `\(\mu_{2.}\)` | | `\(a_3\)` (`easy`) | `\(\mu_{31}\)` | `\(\mu_{32}\)` | `\(\mu_{3.}\)` | |*column mean* | `\(\mu_{.1}\)` | `\(\mu_{.2}\)` | `\(\mu\)` | --- # Row, column and overall average .pull-left[ - Mean of `\(A_i\)` (average of row `\(i\)`): `$$\mu_{i.} = \frac{\mu_{i1} + \cdots + \mu_{in_b}}{n_b}$$` - Mean of `\(B_j\)` (average of column `\(j\)`): `$$\mu_{.j} = \frac{\mu_{1j} + \cdots + \mu_{n_aj}}{n_a}$$` ] .pull-right[ - Overall average (overall all rows and columns): `$$\mu = \frac{\sum_{i=1}^{n_a} \sum_{j=1}^{n_b} \mu_{ij}}{n_an_b}$$` ] --- # Vocabulary of effects .pull-left[ .box-5[Definitions] - .color-5[**simple effects**]: difference between levels of one in a fixed combination of others (change in difficulty for happy ending) - .color-5[**main effects**]: differences relative to average for each condition of a factor (happy vs sad ending) - .color-5[**interaction effects**]: when simple effects differ depending on levels of another factor ] .pull-right[ .box-5[What it means relative to the table] - .color-5[**simple effects**] are comparisons between cell averages within a given row or column - .color-5[**main effects**] are comparisons between row or column averages - .color-5[**interaction effects**] are difference relative to the row or column average ] --- # Marginal effects .pull-left[
happy
sad
column means
$$\mu_{.1}$$
$$\mu_{.2}$$
] .pull-right[
complexity
row means
complicated
$$\mu_{1.}$$
average
$$\mu_{2.}$$
easy
$$\mu_{3.}$$
] --- # Simple effects .pull-left[
happy
sad
means (easy)
$$\mu_{1.}$$
$$\mu_{2.}$$
] .pull-right[
complexity
mean (happy)
complicated
$$\mu_{11}$$
average
$$\mu_{21}$$
easy
$$\mu_{31}$$
] --- # Contrasts Suppose the order of the coefficients is factor `\(A\)` (complexity, 3 levels, complicated/average/easy) and factor `\(B\)` (ending, 2 levels, happy/sad). | test | `\(\mu_{11}\)` | `\(\mu_{12}\)` | `\(\mu_{21}\)` | `\(\mu_{22}\)` | `\(\mu_{31}\)` | `\(\mu_{32}\)` | |:--|--:|--:|--:|--:|--:|--:| | main effect `\(A\)` (complicated vs average) | `\(1\)` | `\(1\)` | `\(-1\)` | `\(-1\)` | `\(0\)` | `\(0\)` | | main effect `\(A\)` (complicated vs easy) | `\(1\)` | `\(1\)` | `\(0\)` | `\(0\)` | `\(-1\)` | `\(-1\)` | | main effect `\(B\)` (happy vs sad) | `\(1\)` | `\(-1\)` | `\(1\)` | `\(-1\)` | `\(1\)` | `\(-1\)` | | interaction `\(AB\)` (comp. vs av, happy vs sad) | `\(1\)` | `\(-1\)` | `\(-1\)` | `\(1\)` | `\(0\)` | `\(0\)` | | interaction `\(AB\)` (comp. vs easy, happy vs sad) | `\(1\)` | `\(-1\)` | `\(0\)` | `\(0\)` | `\(-1\)` | `\(1\)` | --- # Hypothesis tests for main effects Generally, need to compare multiple effects at once .box-inv-5.sp-after-half[ Main effect of factor `\(A\)` ] `\(\mathscr{H}_0\)`: `\(\mu_{1.} = \cdots = \mu_{n_a.}\)` vs `\(\mathscr{H}_a\)`: at least two marginal means of `\(A\)` are different .box-inv-5.sp-after-half[ Main effect of factor `\(B\)` ] `\(\mathscr{H}_0\)`: `\(\mu_{.1} = \cdots = \mu_{.n_b}\)` vs `\(\mathscr{H}_a\)`: at least two marginal means of `\(B\)` are different. --- # Equivalent formulation of the two-way ANOVA Write the model for a response variable `\(Y\)` in terms of two factors `\(a_i\)`, `\(b_j\)`. `$$Y_{ijr} = \mu + \alpha_i + \beta_j + (\alpha\beta)_{ij} + \varepsilon_{ijr}$$` where - `\(\alpha_i = \mu_{i.} - \mu\)` - mean of level `\(a_i\)` minus overall mean. - `\(\beta_j = \mu_{.j} - \mu\)` - mean of level `\(b_j\)` minus overall mean. - `\((\alpha\beta)_{ij} = \mu_{ij} - \mu_{i.} - \mu_{.j} + \mu\)` - the interaction term for `\(a_i\)` and `\(b_j\)`. --- # One average for each subgroup .small[ | `\(\qquad B\)` `ending`<br> `\(A\)` `complexity` `\(\qquad\)` | `\(b_1\)` (`happy`) | `\(b_2\)` (`sad`)| *row mean* | |------------|:----------:|:-----:|:-----:| | `\(a_1\)` (`complicated`) | `\(\mu + \alpha_1 + \beta_1 + (\alpha\beta)_{11}\)` | `\(\mu + \alpha_1 + \beta_2 + (\alpha\beta)_{12}\)` | `\(\mu + \alpha_1\)` | | `\(a_2\)` (`average`) | `\(\mu + \alpha_2 + \beta_1 + (\alpha\beta)_{21}\)` | `\(\mu + \alpha_2 + \beta_2 + (\alpha\beta)_{22}\)` | `\(\mu + \alpha_2\)` | | `\(a_3\)` (`easy`) | `\(\mu + \alpha_3 + \beta_1 + (\alpha\beta)_{31}\)` | `\(\mu + \alpha_3 + \beta_2 + (\alpha\beta)_{32}\)` | `\(\mu + \alpha_3\)` | |*column mean* | `\(\mu + \beta_1\)` | `\(\mu + \beta_2\)` | `\(\mu\)` | ] .box-inv-5[More parameters than data cells!] The model in terms of `\(\alpha\)`, `\(\beta\)` and `\((\alpha\beta)\)` is overparametrized. --- # Sum-to-zero parametrization .box-inv-5[Too many parameters!] Impose sum to zero constraints `$$\sum_{i=1}^{n_a} \alpha_i=0, \quad \sum_{j=1}^{n_b} \beta_j=0, \quad \sum_{j=1}^{n_b} (\alpha\beta)_{ij}=0, \quad \sum_{i=1}^{n_a} (\alpha\beta)_{ij}=0.$$` which imposes `\(1 + n_a + n_b\)` constraints. --- # Why use the sum to zero parametrization? - Testing for main effect of `\(A\)`: `$$\mathscr{H}_0: \alpha_1 = \cdots = \alpha_{n_a} = 0$$` - Testing for main effect of `\(B\)`: `$$\mathscr{H}_0: \beta_1 = \cdots = \beta_{n_b} = 0$$` - Testing for interaction between `\(A\)` and `\(B\)`: `$$\mathscr{H}_0: (\alpha\beta)_{11} = \cdots = (\alpha\beta)_{n_an_b} = 0$$` In all cases, alternative is that at least two coefficients are different. --- # Seeking balance .box-inv-5.sp-after.medium[ **Balanced sample**<br> (equal nb of obs per group) ] .box-inv-5[ With `\(n_r\)` replications per subgroup,<br>total sample size is `\(n = n_an_bn_r\)`. ] --- # Why balanced design? With equal variance, this is the optimal allocation of treatment unit. .box-inv-5.sp-after.medium[maximize power] Estimated means for main and total effects correspond to marginal averages. .box-inv-5.sp-after.medium[equiweighting] Unambiguous decomposition of effects of `\(A\)`, `\(B\)` and interaction. .box-inv-5.sp-after.medium[orthogonality] --- # Rewriting observations `\begin{align*} \underset{\text{obs vs grand mean (total)}}{(y_{ijr} - \widehat{\mu})} &= \underset{\text{row mean vs grand mean} (A)}{(\widehat{\mu}_{i.} - \widehat{\mu})} \\& +\underset{\text{col mean vs grand mean} (B)}{(\widehat{\mu}_{.j} - \widehat{\mu})} \\&+\underset{\text{cell mean vs additive effect} (AB)}{(\widehat{\mu}_{ij} - \widehat{\mu}_{i.} - \widehat{\mu}_{.j}+ \widehat{\mu})} \\&+ \underset{\text{obs vs cell mean (resid)}}{(y_{ijr} - \widehat{\mu}_{ij})} \end{align*}` --- # Decomposing variability Constructing statistics as before by decomposing variability into blocks. We can square both sides and sum over all observations. With balanced design, all cross terms cancel, leaving us with the .color-5[**sum of square**] decomposition `$$\mathsf{SS}_{\text{total}} = \mathsf{SS}_A + \mathsf{SS}_B + \mathsf{SS}_{AB} + \mathsf{SS}_{\text{resid}}.$$` --- # Sum of square decomposition The sum of square decomposition `$$\mathsf{SS}_{\text{total}} = \mathsf{SS}_A + \mathsf{SS}_B + \mathsf{SS}_{AB} + \mathsf{SS}_{\text{resid}}.$$` is an estimator of the population variance decomposition `$$\sigma^2_{\text{total}} = \sigma^2_A + \sigma^2_{B} + \sigma^2_{AB} + \sigma^2_{\text{resid}}.$$` where `\(\sigma^2_A = n_a^{-1}\sum_{i=1}^{n_a} \alpha_i^2\)`, `\(\sigma^2_{AB} = (n_an_b)^{-1} \sum_{i=1}^{n_a} \sum_{j=1}^{n_b} (\alpha\beta)^2_{ij}\)`, etc. Take ratio of variability (effect relative to residual) and standardize numerator and denominator to build an `\(F\)` statistic. --- # Analysis of variance table .small[ | term | degrees of freedom | mean square | `\(F\)` | |------|--------|------|--------| | `\(A\)` | `\(n_a-1\)` | `\(\mathsf{MS}_{A}=\mathsf{SS}_A/(n_a-1)\)` | `\(\mathsf{MS}_{A}/\mathsf{MS}_{\text{res}}\)` | | `\(B\)` | `\(n_b-1\)` | `\(\mathsf{MS}_{B}=\mathsf{SS}_B/(n_b-1)\)` | `\(\mathsf{MS}_{B}/\mathsf{MS}_{\text{res}}\)` | | `\(AB\)` | `\((n_a-1)(n_b-1)\)` | `\(\mathsf{MS}_{AB}=\mathsf{SS}_{AB}/\{(n_a-1)(n_b-1)\}\)` | `\(\mathsf{MS}_{AB}/\mathsf{MS}_{\text{res}}\)` | | residuals | `\(n-n_an_b\)` | `\(\mathsf{MS}_{\text{resid}}=\mathsf{SS}_{\text{res}}/ (n-ab)\)` | | | total | `\(n-1\)` | | ] Read the table backward (starting with the interaction). - If there is a significant interaction, the main effects are **not** of interest and potentially misleading. --- # Intuition behind degrees of freedom | `\(\qquad B\)` `ending`<br> `\(A\)` `complexity` `\(\qquad\)` | `\(b_1\)` (`happy`) | `\(b_2\)` (`sad`)| *row mean* | |------------|:----------:|:-----:|:-----:| | `\(a_1\)` (`complicated`) | `\(\mu_{11}\)` | `\(\mathsf{X}\)` | `\(\mu_{1.}\)` | | `\(a_2\)` (`average`) | `\(\mu_{21}\)` | `\(\mathsf{X}\)` | `\(\mu_{2.}\)` | | `\(a_3\)` (`easy`) | `\(\mathsf{X}\)` | `\(\mathsf{X}\)` | `\(\mathsf{X}\)` | |*column mean* | `\(\mu_{.1}\)` | `\(\mathsf{X}\)` | `\(\mu\)` | .small[ Terms with `\(\mathsf{X}\)` are fully determined by row/column/total averages ] --- # Multiplicity correction With equal sample size and equal variance, usual recipes for ANOVA hold. Correction depends on the effect: e.g., for factor `\(A\)`, the critical values are - Bonferroni: `\(1-\alpha/(2m)\)` quantile of `\(\mathsf{St}(n-n_an_b)\)` - Tukey: Studentized range (`qtukey`) - level `\(1-\alpha/2\)`, `\(n_a\)` groups, `\(n-n_an_b\)` degrees of freedom. - Scheffé: critical value is `\(\{(n_a-1) \mathfrak{f}_{1-\alpha}\}^{1/2}\)` - `\(\mathfrak{f}_{1-\alpha}\)` is `\(1-\alpha\)` quantile of `\(\mathsf{F}(\nu_1 = n_a-1, \nu_2 = n-n_an_b)\)`. Software implementations available in `emmeans` in **R**. --- layout: false name: factorial-designs class: center middle section-title section-title-5 animated fadeIn # Numerical example