ANOVA
One-factor ANOVA by example 2
One-factor ANOVA by visual inspection 3
4 One-factor ANOVA H 0 H 0 : µ 1 = µ 2 = µ 3 = H A : not all means are equal
5 One-factor ANOVA but why not t-tests t-tests? 3+2+1 tests -> multiple comparisons The variance is not correctly estimated We need a method that uses the full dataset
6 One-factor ANOVA the cook book I Find the Within groups SS Fx: SS1 = x i x 2 i = 8.2 6 2 + 8.2 7 2 + 8.2 8 2 + 8.2 8 2 + 8.2 9 2 + 8.2 11 2 = 14.4 Sum the sum of squares from each group: SS1+SS2+SS3+SS4 = 14.4+8.8+20.8+13.3 =57.8 df = 20 Within group variance (residual variance) within group SS = = 57.8 = 2.9 df 20 Assumptions: Data is normal distributed and the variance is equal in the groups
7 One-factor ANOVA the cook book II Find the total SS SStot = x i x 2 df = 23 i = 140.0 Find the between group SS (group mean) SSbetween = n x x 2 df = 3 s 2 = m = 6( 8.2 7.5 2 + 5.8 7.5 2 + 10.2 7.5 2 + 5.7 7.5 2 ) = 82.1 between group SS df = 82.1 3 = 27.4
8 The ANOVA table Outcome Sum of Squares ANOVA df Mean Square F Sig. Between Groups 82,125 3 27,375 9,467,0004 Within Groups 57,833 20 2,892 Total 139,958 23 Variance aka mean square aka s 2 is simply SS/df F is the Between SS divided by the Within SS
9 Assumptions The data needs to be normal distributed in the groups The variance needs to be equal in all groups: homoscedasticity The groups needs to be independent
10 Multiple comparisons procedures aka post hoc analysis Rejecting H 0 only states that one or more pairs of means are different, but not which. Tukeys multiple comparisons test as an example.
11 Tukeys multiple comparisons Rank the sample means: Rank 1 2 3 4 Group 3 1 2 4 µ 10.2 8.2 5.8 5.7 SE = s2 n = 2,892 = 0,67 6 pair difference q H 0 3vs4 4.5 6,7 reject 3vs2 4,4 6,6 reject 3vs1 2 3,0 Do not reject 1vs4 2,5 3,7 Do not reject 1vs2 Don not test Do not reject 2vs4 Don not test Do not reject q = X 4 X 3 SE > 3,958? Outcome Sum of Squares ANOVA df Mean Square F Sig. Between Groups 82,125 3 27,375 9,467,000 Within Groups 57,833 20 2,892 Total 139,958 23
Tukeys multiple comparisons 12
1-way ANOVA in SPSS 13
14 Exercise Is there i difference in the group mean? Group 1 Group 2 Group 3 28,00 34,00 33,00 20,00 30,00 38,00 27,00 41,00 27,00 29,00 17,00 36,00 36,00 28,00 25,00
15 Comparison between several medians Kruskal-Wallis test H 0 : The distribution of the groups are equal 1-Way ANOVA for non-normal data
16 Kruskal-Wallis test A few definitions: k is the number of groups n i: : the numner of observations in the i th group. N : total numner of observations R i : the sum of ranks in the i th group How to: Rank all observations Calculate the rank sum for each group Calculate H H is chi-square distributed with k-1 degrees of redom Look up the p-value in a table H 12 2 Ti ni 3 N N 1 N 1
Kruskal-Wallis test An example 17
18 Kruskal-Wallis test An example The data is ranked
19 Kruskal-Wallis test An example The data is ranked H is calculated 12 H 42 2 53 2 36 12 2422 321 69,2 63 6,2 2021 2 20 20 1 79 2 5 3 20 1
20 Kruskal-Wallis test An example The data is ranked H = 6,2 # d.f. = k-1 = 3
Kruskal-Wallis test in SPSS table7-1 21
Kruskal-Wallis test i SPSS 22
23 Kruskal-Wallis test i SPSS Ranks group N Mean Rank count 1,00 5 8,40 2,00 5 10,60 3,00 5 7,20 4,00 5 15,80 Total 20 Test Statistics a,b count Chi-Square 6,205 df 3 Asymp. Sig.,102 a. Kruskal Wallis Test b. Grouping Variable: group
24 Two-factor ANOVA with equal replications Experimental design: 2 2 (or 2 2 ) factorial with n = 5 replicate Total number of observations: N = 2 2 5 = 20 Equal replications also termed orthogonality
25 The hypothesis H 0 : There is on effect of hormone treatment on the mean plasma concentration H 0 : There is on difference in mean plasma concentration between sexes H 0 : There is on interaction of sex and hormone treatment on the mean plasma concentration Why not just use one-way ANOVA with for levels?
26 How to do a 2-way ANOVA with equal replications Calculating means Calculate cell means: n Calculate the total mean (grand mean) Calculating treatment means 5 5 X 16,3 20,4 12,4 15,8 9,5 n l1 abl l1 11l X ab eg X X i n X a b i1 j1 l1 b N n j1 l1 bn X n ijl X ijl egx 21,825 1 13,5 14,88
27 How to do a 2-way ANOVA with equal replications Calculating general Sum of Squares Calculate total SS: totalss totaldf N a b i1 j1 l1 1 19 n X ijl X 2 1762,7175 Calculate the cell SS cells SS a n i 1 j 1 cells DF ab 1 3 b X ij X 2 1461,3255 Calculating within-cells error SS within - cells (error)ss n within - cells (error) DF ab a b i1 j1 l1 n 1 16 n X ijl X ij 2 301,3920
28 How to do a 2-way ANOVA with equal replications Calculating factor Sum of Squares Calculating factor A SS: factor A SS factor A DF a 1 1 a bn X i i 1 X 2 1386,1125 Calculating factor B SS factor BSS factor B DF b 1 1 b 1 an X j j X 2 70,3125 Calculating A B interaction SS A B interaction SS = cell SS factor A SS factor B SS = 4,9005 A B DF = cell DF factor A DF factor B DF = 1
How to do a 2-way ANOVA with equal replications Summary of calculations 29
30 How to do a 2-way ANOVA with equal replications Hypothesis test H 0 : There is on effect of hormone treatment on the mean plasma concentration F = hormone MS/within-cell MS = 1386,1125/18,8370 = 73,6 F 0,05(1),1,16 = 4,49 H 0 : There is on difference in mean plasma concentration between sexes F = sex MS/within-cell MS = 3,73 F 0,05(1),1,16 = 4,49 H 0 : There is on interaction of sex and hormone treatment on the mean plasma concentration F = A B MS/within-cell MS = 0,260 F 0,05(1),1,16 = 4,49
31 Visualizing 2-way ANOVA Table 12.2 and Figure 12.1
2-way ANOVA in SPSS 32
33 2-way ANOVA in SPSS Click Add
Visualizing 2-way ANOVA without interaction 34
Visualizing 2-way ANOVA with interaction 35
36 2-way ANOVA Random or fixed factor Random factor: Levels are selected at random Fixed factor: The value of each levels are of interest and selected on purpose.
37 2-way ANOVA Assumptions Independent levels of the each factor Normal distributed numbers in each cell Equal variance in each cell Bartletts homogenicity test (Section 10.7) s 2 ~ within cell MS; ~ within cell DF The ANOVA test is robust to small violations of the assumptions Data transformation is always an option (see chpter 13) There are no non-parametric alternative to the 2-way ANOVA
38 2-way ANOVA Multiple Comparisons Multiple comparisons tests ~ post hoc tests can be used as in one-way ANOVA Should only be performed if there is a main effect of the factor and no interaction
39 2-way ANOVA Confidence limits for means 95 % confidence limits for calcium concentrations on in birds without hormone treatment 2 s 95 % CI X1 t0,05(2), bn within cell DF;s 2 within cell MS
40 2-way ANOVA With proportional but unequal replications Proportional replications: n ij #row i# col j N
41 2-way ANOVA With disproportional replications Statistical packges as SPSS has porcedures for estimating missing values and correcting unballanced designs, eg using harmonic means Values should not be estimated by simple cell means Single values can be estimated, but remember to decrease the DF a b nij aai bb j ˆ i1 j1l 1 ijl X N 1 a b X ijl
42 2-way ANOVA With one replication Get more data!
2-way ANOVA Randomized block design 43
44 2-way ANOVA Repeated measures Repeating measurements in the same subject, like a paired t-test An additional assumption is that the correlation between pairs of groups is equal: compound symmetry if this is not the case, try multivariate ANOVA or linear mixed model