4.1 Contingency Table
A contingency table is used when results are put in cells as: Rows and Columns.
| a | b | \(R_1\) |
| c | d | \(R_2\) |
| \(C_1\) | \(C_2\) | \(g\) |
\(\therefore \) a \(2\times 2\) contingency table has 1 df.
| \(c_1R_1/g\) | \(c_1R_2/g\) |
| \(c_1R_2/g\) | \(c_2R_2/g\) |
The table below shows the result of prevention of a disease by vaccination
| Attacked | Not Attacked | ||
| Vaccinated | 20 | 50 | 70 |
| Not Vaccinated | 15 | 15 | 30 |
| 35 | 65 | 100 |
Test the hypothesis that vaccination is effective against the disease.
Solution.
| \(\frac {35\times 70}{100}\) | \(\frac {65\times 70}{100}\) |
| \(\frac {35\times 30}{100}\) | \(\frac {65\times 30}{100}\) |
The \(\chi ^2\) distribution depends on the df, therefore we write \(\chi ^2_v\). That is \(v=n-1\) is called degree of freedom is the number of expected frequencies which can be varied independently \(2\times 2\) contingency table has \(v=1\) df because a column loses 1 df and the rows lose 1 df to give \(v=(2-1)(2-1)\). The table below shows the seven results for a random sample of 4146 people on the type of house and compound.
Example 4.1. The table records the type of housing occupied by households in three compounds. Test at \(\alpha =5\%\) whether the type of housing varies between the compounds.
Solution.
- 1.
- Set up the hypothesis
\(H_0:\) The type of housing and compound are independent.
\(H_1:\) The type of housing and compound are dependent. - 2.
- Level of significance \(\alpha =5\%\).
- 3.
- Test statistic. Each expected frequency is
\[e_{ij}=\frac {(\text {row total})\times (\text {column total})}{\text {grand total}}\]
so, for instance, \(e_{11}=\frac {754\times 973}{4266}=171.97\).
Detail Data Flats Chelstone 171.97 301.88 280.14 Northmead 217.59 381.96 354.45 Kabwata 583.44 1024.16 950.41 Table 32: Expected frequencies under \(H_0\). Each row and column still totals what it did before — a useful check. Then \[\chi ^2=\sum \frac {(O-e)^2}{e} =\frac {(95-171.97)^2}{171.97}+\frac {(297-301.88)^2}{301.88}+\cdots +\frac {(861-950.41)^2}{950.41}=103.96\]
- 4.
- Critical region. With \(r=3\) rows and \(c=3\) columns, \[v=(r-1)(c-1)=2\times 2=4\] and from tables \(\chi ^2_{4,\,0.05}=9.488\). We reject \(H_0\) if \(\chi ^2>9.488\).
- 5.
- Conclusion. \(103.96>9.488\), so we reject \(H_0\): the type of housing does vary between the compounds.
Where the difference lies is worth reading off the table rather than leaving at “significant”. Chelstone has \(95\) detached houses against \(172\) expected and \(362\) flats against \(280\); Kabwata has \(703\) detached against \(583\). Those three cells alone contribute \(34.5+23.9+24.5=82.9\) of the total \(103.96\). The compounds differ mainly in the balance between detached houses and flats, not across the board.
Analysis of variance is used to check the variability of more than two samples since we can not use the
four
\(H_0:\mu _1=\mu _2\)
\(H_1:\mu _1\neq \mu _2\)
\(\mu _1>\mu _2\)
\(\mu _1<\mu _2\)
\((*)\) One way ANOVA is used for either column or row
\((*)\) Two way ANOVA is used fro resting both rows and columns.
\(H_0:\) There is no difference between fertilizers
\(\mu _1=\mu _2=\mu _3=\mu _4\), \((\mu _i=\mu )\hspace {0.1cm}i=1,2,3,4\)
\(H_1:\) At least two fertilizers are different \((\mu _i \neq \mu )\)
Write \(x_{ij}\) for the \(j\)th observation in the \(i\)th group, \(T_j\) for each group total and \(T\) for the grand total. The quantities we need are: \begin {align*} T(\text {sum of all n observations}) & = T =\sum x_{ij}\\\\ SS_T = \text {Total sum of squares} &= SS_T = \sum x^2_{ij}-\frac {T^2}{n}\\\\ SS_B = \text {Between samples sum of squares} & = SS_B = \sum _{j=1}^{k}\frac {T_j^2}{n_j}-\frac {T^2}{n}\\\ SS_W = \text {Within sample sum of squares} &= SS_W =SS_T - SS_B\\\\ MS_{\varepsilon } & =\text {mean square error} = \frac {SS_W}{n-k}\\ \end {align*}
| Squares of Variance | SS | df | MS | F-statistics |
| Between Sample | \(SS_B\) | \(v_1=k-1\) | \(\frac {SS_B}{k-1}=MS_B\) | \(F-\frac {MS_B}{MS_{\varepsilon }}\) |
| Within Sample | \(SS_{\varepsilon }\) | \(v_2=n-k\) | \(\frac {SS_{\varepsilon }}{n-k}=MS_{\varepsilon }\) | |
| Total | \(SS_T\) | \(n-1\) | ||
Example 4.2. Three fertilisers were each applied to four plots, and the yields recorded. Test at \(\alpha =5\%\) whether the mean yield differs between fertilisers.
Solution.
- 1.
- Set up the hypothesis
\(H_0: \mu _1=\mu _2=\mu _3\)
\(H_1:\) at least two of the means differ - 2.
- Level of significance \(\alpha =5\%\)
- 3.
- Test statistic. Here \(k=3\) groups, \(n_j=4\) each and \(n=12\), with grand total \(T=8+14+12=34\), so the correction factor is
\[\frac {T^2}{n}=\frac {34^2}{12}=\frac {1156}{12}=96.333\]
\begin {align*} SS_T &=\sum x_{ij}^2-\frac {T^2}{n}=\Big [3^2+2^2+1^2+\cdots +1^2\Big ]-96.333=118-96.333=21.667\\\\ SS_B &=\sum _{j=1}^{k}\frac {T_j^2}{n_j}-\frac {T^2}{n}=\frac {8^2+14^2+12^2}{4}-96.333=\frac {404}{4}-96.333=4.667\\\\ SS_W &=SS_T-SS_B=21.667-4.667=17.000 \end {align*}
Source SS df MS \(F\) Between samples 4.667 \(k-1=2\) \(4.667/2=2.333\) \(2.333/1.889=1.235\) Within samples 17.000 \(n-k=9\) \(17.000/9=1.889\) Total 21.667 \(n-1=11\) Table 34: ANOVA table for the fertiliser data. Note that the degrees of freedom add up, \(2+9=11\), and so do the sums of squares. If they do not, there is an arithmetic slip somewhere above.
- 4.
- Critical region. From tables \(F_{2,\,9,\,0.05}=4.26\), so we reject \(H_0\) if \(F>4.26\).
- 5.
- Conclusion. \(F=1.235<4.26\), so we fail to reject \(H_0\). There is no evidence at the \(5\%\) level that the three fertilisers differ in mean yield.
Look at where the variation went. Of the total \(21.667\), only \(4.667\) lies between the fertilisers and \(17.000\) lies within them — plot-to-plot differences under the same fertiliser are far larger than the differences between fertilisers. That is what \(F\) compares, and it is why the test comes out as it does.
Assumptions Made In Analysis Of Variance
- 1.
- The \(k\) parent populations from which the samples are drawn are normally distributed with respective means \(\mu _1, \mu _2, \ldots , \mu _k\).
- 2.
- The samples drawn are randomly and independently.
- 3.
- The population have equal and stable variances (Homoscedasticity).
- 4.
- The effects are additive. This means that \(x_{ij}\), the j\(^{\text {th}}\) observation in the i\(^{\text {th}}\) sample or the class
or made up of class an overall effect \(\mu \).
Sum of squares identity \(SS_T = SS_B + SS_W\) \[\underbrace {\sum _{i=1}^k \sum _{j=1}^{n_i}(x_{ij}-\overline {\overline {x}})^2}_{SS_T} =\underbrace {\sum _{i=1}^k n_i(\overline {x}_i-\overline {\overline {x}})^2}_{SS_B} +\underbrace {\sum _{i=1}^k\sum _{j=1}^{n_i}(x_{ij}-\overline {x}_i)^2}_{SS_W}\]
Read it as the sentence it is: the total spread of every observation about the grand mean splits exactly into the spread between group means and the spread within groups. The two right-hand terms must use different centres – the grand mean \(\overline {\overline {x}}\) for the first, each group’s own mean \(\overline {x}_i\) for the second – and that is the whole content of the identity. Using the same centre in both would not add up.
Proof. The trick is to add and subtract the group mean \(\overline {x}_i\), so that each deviation from the grand mean splits into two pieces: \[x_{ij}-\overline {\overline {x}}=\big (\overline {x}_i-\overline {\overline {x}}\big )+\big (x_{ij}-\overline {x}_i\big )\] Squaring and summing, \begin {align*} \sum _{i=1}^k\sum _{j=1}^{n_i}(x_{ij}-\overline {\overline {x}})^2 &=\sum _{i=1}^k\sum _{j=1}^{n_i}\Big [(\overline {x}_i-\overline {\overline {x}})+(x_{ij}-\overline {x}_i)\Big ]^2\\\\ &=\sum _{i=1}^k\sum _{j=1}^{n_i}\Big [(\overline {x}_i-\overline {\overline {x}})^2+(x_{ij}-\overline {x}_i)^2 +2(\overline {x}_i-\overline {\overline {x}})(x_{ij}-\overline {x}_i)\Big ]\\\\ &=\sum _{i=1}^k n_i(\overline {x}_i-\overline {\overline {x}})^2+\sum _{i=1}^k\sum _{j=1}^{n_i}(x_{ij}-\overline {x}_i)^2 +2\sum _{i=1}^k(\overline {x}_i-\overline {\overline {x}})\sum _{j=1}^{n_i}(x_{ij}-\overline {x}_i) \end {align*}
The identity only works because that last term is zero. In the inner sum \((\overline {x}_i-\overline {\overline {x}})\) is a constant, so it comes
outside, and what is left is
\[\sum _{j=1}^{n_i}(x_{ij}-\overline {x}_i)=0\]
since deviations about their own mean always cancel. The whole cross-product term therefore
vanishes, leaving
\[SS_T = SS_B + SS_W\hspace {1cm}\blacksquare \]
| \(T_1\) | \(T_2\) | \(T_3\) | \(T_4\) | \(T_5\) | ||
| \(R_1\) | 5 | 9 | 3 | 2 | 7 | 26 |
| \(R_2\) | 4 | 7 | 5 | 3 | 7 | 26 |
| \(R_3\) | 8 | 8 | 2 | 4 | 9 | 31 |
| \(R_4\) | 6 | 6 | 3 | 1 | 4 | 20 |
| \(R_5\) | 3 | 9 | 7 | 4 | 7 | 30 |
| 26 | 39 | 20 | 14 | 34 | 133 = q | |
| \(C_1\) | \(C_2\) | \(C_3\) | \(C_4\) | \(C_5\) | ||
Test whether there is any significance difference between the treatment and \(\alpha = 0.025\)
- 1.
- Set up the hypothesis
\(H_0:\) \(\mu _1=\mu _2=\mu _3=\mu _4=\mu _5\)
\(H_1:\) At least two are different
- 2.
- We set \(\alpha = 0.05\)
\(N=rc=5\times 5=25\) \[\text {Correction factor}\hspace {0.5cm}=\frac {g^2}{N}=\frac {133^2}{25}\hspace {1cm}\implies cf = 707.56\] - 3.
- Test statistic \begin {align*} SS_T & =\sum \sum x^2_{ij}-cf\\ &=\Big [5^2+9^2+3^2+2^2+\cdots +7^2\Big ]-707.56\\ &=863-707.56\\ \implies \hspace {1cm} SS_T &=155.5 \end {align*}
\begin {align*} SS_C & = \frac {1}{r}\sum t_i^2-cf\\ &=\frac {1}{5}\Big [26^2+39^2+20^2+14^2+34^2\Big ]-707.56\\ &=\frac {1}{5}[3949]-707.56\\\\ \implies \hspace {0.5cm }SS_C &=82.3 \end {align*}
\begin {align*} SS_T &=SS_C +SS_E\\\\ \implies \hspace {0.5cm} SS_E &= SS_T-SS_C\\ &=155.5-82.3 \\ &=73.2 \end {align*}
| Source of Variation | df | SS | MS | F |
| Columns | \(c-1=4=v_1\) | 82.3 | \(MS=\frac {82.3}{4}=20.57\) | \(F=\frac {MSC}{MSE}=\frac {20.57}{3.66}\) |
| Error | \((rc-1)-(c-1)\) | 73.2 | \(MSE=\frac {73.2}{20}=3.60\) | \(F=5.62\) |
| \(=24-4=20=v_2\) | ||||
\[F_{v_1,v_2,{\alpha }}=F_{4,20,0.05}=5.80\]
We accept \(H_0\) and \(H_1\), since our statistic \(F=5.60\) lies in the acceptance region.
\(\implies \hspace {0.5cm}\) There is no difference between them.
| Source of Variation | df | SS | MS | F |
| Between Rows | \(r-1=v_1=3\) | \(SS_R\) | \(\frac {SS_R}{r-1}=MS_R\) | \(F_R=\frac {MS_R}{MSE}\) |
| Withing the Columns | \(c-1=v_2=2\) | \(SS_C\) | \(\frac {SS_C}{c-1}=MS_C\) | \(F_C=\frac {MS_C}{MSE}\) |
| Errors | \((rc-1)-(c-1)-(r-1)\) | \(SSE\) | \(\frac {SSE}{v_3}=MSE\) | |
| Total | \(rc-1=v_3=6\) | |||
\[SSE = SST-SS_R-SS_C\]
The data below gives the results of variate of the maize against these types of fertilizers.
| variate | ||||
| \(v_1\) | \(v_2\) | \(v_3\) | ||
| \(f_1\) | 17 | 25 | 25 | 69 |
| \(f_2\) | 8 | 10 | 0 | 18 |
| \(f_3\) | 12 | 19 | 11 | 42 |
| \(f_4\) | 11 | 10 | 6 | 27 |
| Total | 156 |
Do the data provide evidence at \(\alpha =1\%\) that
- \(\longrightarrow \)
- there is a different between the variates
- \(\longrightarrow \)
- there is a difference between the fertilizers
- 1.
- Calculate the correction factor \(\displaystyle {cf=\frac {g^2}{rc}}\)
- 2.
- Total sum of the squares \(\displaystyle {SS_T=\sum \sum ^k_{ij}x^2_{ij}-cf}\)
- 3.
- Sum of squares of columns \(\displaystyle {SS_C=\frac {1}{r}\sum c^2-cf}\)
- 4.
- Sum of square of rows \(\displaystyle {SS_R=\frac {1}{c}\sum r^2_i-cf}\)
- 5.
- \(SSE=SS_T-SS_R-SS_C\)
\[df: v_1=2, v_2=3, v_3=6\] \begin {align*} &(rc-1)-(r-1)-(c-1)\\ &(12-1)-(4-1)-(3-1)\\ &11-3-5\\ &6=v_3 \end {align*}
\[\text {We have that}\hspace {0.3cm} F(\text {Row})=F_{{0.05},3,6}=4.76\hspace {0.3cm} \text {and}\hspace {0.3cm}F(\text {Column})=F_{0.05,2,6}=5.14\]
Reject \(H_0\)
The Least Significant Difference Test (LSD) \[\text {The test statistic for the LSD is}\hspace {0.5cm} \text {LSD}=t_{\alpha ,v}\hspace {0.1cm}\times \hspace {0.1cm}\sqrt {\frac {1}{n_1}+\frac {1}{n_2}}\hspace {0.3cm},\hspace {0.5cm} v=(n_1+n_2)-2\]
We shall use \(\hat {S}=MSE\)
When \(H_0\) is rejected we proceed further for LSD test otherwise not
| 1 | 2 | 3 | 4 | 5 | 6 | ||
| 1 | 1 | 3 | 6 | 4 | 3 | 2 | |
| 2 | 1 | 4 | 4 | 8 | 5 | 1 | |
| 3 | 3 | 6 | 7 | 8 | 4 | 3 | |
| 4 | 2 | 3 | 2 | 3 | 2 | 1 | |
| 7 | 16 | 19 | 23 | 14 | 7 | 81 | |
| Mean | 1.75 | 4.0 | 4.75 | 5.75 | 3.5 | 1.75 | |
| Total | |||||||
A significant \(F\) says only that the treatment means are not all equal. It does not say which ones differ.
The least significant difference compares them a pair at a time:
\[LSD = t_{\alpha /2,\;df_{error}}\times \sqrt {MSE\left (\frac {1}{n_i}+\frac {1}{n_j}\right )}\]
Any pair of means further apart than the \(LSD\) is declared significantly different.
Example 4.3. Following an analysis of variance with \(MSE=1.57\) on \(6\) degrees of freedom and four treatment
means each based on \(n=4\) observations, the differences from \(v_1\) are
\[v_2-v_1=2.25,\hspace {1cm} v_3-v_1=3.00,\hspace {1cm} v_4-v_1=4.00\]
Which treatments differ from \(v_1\) at the \(5\%\) level?
Solution. From tables \(t_{0.025,\,6}=2.447\), so \begin {align*} LSD &= 2.447\times \sqrt {1.57\left (\frac {1}{4}+\frac {1}{4}\right )}\\\\ &= 2.447\times \sqrt {0.785}\\\\ &= 2.447\times 0.886 = 2.168 \end {align*}
Comparing each difference against \(2.168\):
- \(v_2-v_1=2.25>2.168\), so \(v_1\) and \(v_2\) differ significantly.
- \(v_3-v_1=3.00>2.168\), so \(v_1\) and \(v_3\) differ significantly.
- \(v_4-v_1=4.00>2.168\), so \(v_1\) and \(v_4\) differ significantly.
All three exceed the \(LSD\), so \(v_1\) differs from each of the others. Note that \(v_2-v_1\) only just clears the bar, at \(2.25\) against
\(2.168\); a conclusion resting on that small a margin should be reported as such rather than stated
flatly.
4.1.1 Design of Experiments
| A | B | D | C |
| D | A | C | D |
| C | D | A | B |
Randomized Block design
Questions on this section
Stuck on something here? Ask below and it stays attached to this topic.