# ANOVA (Analysis of Variance)

## Presentation on theme: "ANOVA (Analysis of Variance)"โ Presentation transcript:

ANOVA (Analysis of Variance)
Martina Litschmannovรก K210

The basic ANOVA situation
Two variables: 1 Categorical, 1 Quantitative Main Question: Do the (means of) the quantitative variables depend on which group (given by categorical variable) the individual is in? If categorical variable has only 2 values: null hypothesis: ๐ 1 โ ๐ 2 =๐ท ANOVA allows for 3 or more groups

An example ANOVA situation
Subjects: 25 patients with blisters Treatments: Treatment A, Treatment B, Placebo Measurement: # of days until blisters heal Data [and means]: A: 5,6,6,7,7,8,9, [7.25] B: 7,7,8,9,9,10,10, [8.875] P: 7,9,9,10,10,10,11,12,13 [10.11] Are these differences significant?

Informal Investigation
Graphical investigation: side-by-side box plots multiple histograms Whether the differences between the groups are significant depends on the difference in the means the standard deviations of each group the sample sizes ANOVA determines p-value from the F statistic

Side by Side Boxplots

What does ANOVA do? At its simplest (there are extensions) ANOVA tests the following hypotheses: H0: The means of all the groups are equal. HA: Not all the means are equal. Doesnโt say how or which ones differ. Can follow up with โmultiple comparisonsโ. Note: We usually refer to the sub-populations as โgroupsโ when doing ANOVA.

Assumptions of ANOVA each group is approximately normal
check this by looking at histograms and/or normal quantile plots, or use assumptions can handle some nonnormality, but not severe outliers test of normality standard deviations of each group are approximately equal rule of thumb: ratio of largest to smallest sample st. dev. must be less than 2:1 test of homoscedasticity

Normality Check We should check for normality using:
assumptions about population histograms for each group normal quantile plot for each group test of normality (Shapiro-Wilk, Liliefors, Anderson- Darling test, โฆ) With such small data sets, there really isnโt a really good way to check normality from data, but we make the common assumption that physical measurements of people tend to be normally distributed.

Shapiro-Wilk test One of the strongest tests of normality. [Shapiro, Wilk] Online computer applet (Simon Ditto, 2009) for this test can be found here.

Standard Deviation Check
Variable treatment N Mean Median StDev days A B P Compare largest and smallest standard deviations: largest: 1,764 smallest: 1,458 1,764/1,458=1,210<2 OK Note: Std. dev. ratio greather then 2 signs heteroscedasticity.

ANOVA Notation Number of Individuals all together : ๐= ๐=1 ๐ ๐ ๐ ,
Group 1 2 โฆ k Sample ๐ 11 ๐ 12 ๐ 1๐ โฎ ๐ ๐ 1 1 ๐ ๐ 2 2 ๐ ๐ ๐ ๐ Sample Size ๐ 1 ๐ 2 ๐ ๐ Sample average ๐ 1 ๐ 2 ๐ ๐ Sample Std. Deviation ๐  1 ๐  2 ๐  ๐ Number of Individuals all together : ๐= ๐=1 ๐ ๐ ๐ , Sample means: ๐ ๐ = 1 ๐ ๐ ๐=1 ๐ ๐ ๐ ๐๐ , Grand mean: ๐ = 1 ๐ ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ , Sample Standard Deviations: ๐  ๐ 2 = 1 ๐ ๐ โ1 ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ ๐

Levene Test Null and alternative hypothesis:
H0: ๐ 1 2 = ๐ 2 2 =โฏ= ๐ ๐ 2 , HA: ๐ป 0 Test Statistic: ๐น ๐ = ๐๐ ๐๐ต ๐โ1 ๐๐ ๐๐ ๐โ๐ , where ๐ ๐๐ = ๐ ๐๐ โ ๐ ๐ , ๐ ๐ = ๐=1 ๐ ๐ ๐ ๐๐ ๐ ๐ , ๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ ๐ , ๐๐ ๐๐ต = ๐=1 ๐ ๐ ๐ ๐ ๐ โ ๐ 2 , ๐๐ ๐๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ ๐ p-value:ย ๐โ๐ฃ๐๐๐ข๐=1โ ๐น 0 ๐ฅ ๐๐ต๐ , where ๐น 0 ๐ฅ is CDF of Fisher-Snedecor distribution with ๐โ1, ๐โ๐ degrees of freedom.

How ANOVA works (outline)
ANOVA measures two sources of variation in the data and compares their relative sizes.

How ANOVA works (outline)
Sum of Squares between Groups, ย  ๐๐ ๐ต = ๐=1 ๐ ๐ ๐ ๐ ๐ โ ๐ 2 , ย  resp. Mean of Squares โ between groups ๐๐ ๐ต = ๐๐ ๐ต ๐โ1 , where ๐โ1 is degrees of freedom ๐๐ ๐ต . Sum of Squares โ errors ๐๐ ๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ ๐ 2 = ๐=1 ๐ ๐ ๐ โ1 ๐  ๐ 2 , ย  resp. Mean of squares - error ๐๐ ๐ = ๐๐ ๐ ๐โ๐ , where ๐โ๐ is degrees of freedom ๐๐ ๐ . Difference between Means Difference within Groups

The ANOVA F-statistic is a ratio of the Between Group Variaton divided by the Within Group Variation: ๐น= ๐๐ ๐ต ๐๐ ๐ A large F is evidence against H0, since it indicates that there is more difference between groups than within groups.

ANOVA Output Source of Variation SS DF MS F p-value Between Groups
34,74 2 17,37 6,45 0,006 Within Groups 59,26 22 2,69 Total 94,00 24

Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups ๐๐ ๐ต = ๐=1 ๐ ๐ ๐ ๐ ๐ โ ๐ 2 ๐๐ ๐ต =๐โ1 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups ๐๐ ๐ = ๐=1 ๐ ๐ ๐ โ1 ๐  ๐ 2 ๐๐ ๐ =๐โ๐ ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total ๐๐ ๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ 2 ๐๐ ๐ =๐โ1

Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Count Average Variance <35 let 53 25, , let , ,2775 >50 let 76 26, , Total , ,8971

Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Assumptions: Normality Homoskedasticita H0: ๐ 1 2 = ๐ 2 2 = ๐ 3 2 , HA: ๐ป 0 , ๐โ๐ฃ๐๐๐ข๐=0,129 (Levene test)

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Count Average Variance <35 let , ,3825 let , ,2775 >50 let , ,3393 Total , ,8971 ๐๐ ๐ต = ๐=1 ๐ ๐ ๐ ๐ ๐ โ ๐ 2 =53โ 25,1โ25, โ 25,9โ25, +76โ 26,1โ25,8 2 =34,0 ๐๐ ๐ = ๐=1 ๐ ๐ ๐ โ1 ๐  ๐ 2 =52โ10,4+122โ16,3+75โ12,3=3451,9

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups ๐๐ ๐ต = ๐=1 ๐ ๐ ๐ ๐ ๐ โ ๐ 2 ๐๐ ๐ต =๐โ1 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups ๐๐ ๐ = ๐=1 ๐ ๐ ๐ โ1 ๐  ๐ 2 ๐๐ ๐ =๐โ๐ ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total ๐๐ ๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ 2 ๐๐ ๐ =๐โ1

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 ๐๐ ๐ต =๐โ1 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups 3451,9 ๐๐ ๐ =๐โ๐ ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total ๐๐ ๐ = ๐=1 ๐ ๐=1 ๐ ๐ ๐ ๐๐ โ ๐ 2 ๐๐ ๐ =๐โ1

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 ๐๐ ๐ต =๐โ1 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups 3451,9 ๐๐ ๐ =๐โ๐ ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total 3485,9 ๐๐ ๐ =๐โ1

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 ๐๐ ๐ต =๐โ1 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups 3451,9 ๐๐ ๐ =๐โ๐ ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total 3485,9 ๐๐ ๐ =๐โ1 k โฆ number of sanmples ๐=3 n โฆ total sample si๐ง๐ ๐=252

Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 2 ๐๐ ๐ต = ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups 3451,9 249 ๐๐ ๐ = ๐๐ ๐ ๐๐ ๐ --- Total 3485,9 251 / = / =

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 2 17,0 ๐๐ ๐ต ๐๐ ๐ 1โ ๐น 0 ๐ฅ ๐๐ต๐ Within Groups 3451,9 249 13,9 --- Total 3485,9 251

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 2 17,0 1,23 0,294 Within Groups 3451,9 249 13,9 --- Total 3485,9 251 ๐โ๐ฃ๐๐๐ข๐=1โ๐น 1,23 =0,294 , where F(x) is CDF of Fisher-Snedecor distribution with 2 , 249 degrees of freedom

Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0
Using the results of exploratory analysis and ANOVA test, verify that the age of a statistically significant effect on BMI. Null and alternative hypothesis: H0: ๐ 1 = ๐ 2 = ๐ 3 , HA: ๐ป 0 Calculating of p-value: Result: We dont reject null hypothesis at the significance level 0,05. There is not a statistically significant difference between the means of BMI depended on the age. Source of Variation Sum of Squares Degrees of Freedom Mean of Squares ๐น ๐โ๐ฃ๐๐๐ข๐ Between Groups 34,0 2 17,0 1,23 0,294 Within Groups 3451,9 249 13,9 --- Total 3485,9 251

Whereโs the Difference?
Once ANOVA indicates that the groups do not all appear to have the same means, what do we do? Analysis of Variance for days Source DF SS MS F P treatmen Error Total Individual 95% CIs For Mean Based on Pooled StDev Level N Mean StDev A ( * ) B ( * ) P (------* ) Pooled StDev = Clearest difference: P is worse than A (CIโs donโt overlap)

Multiple Comparisons Once ANOVA indicates that the groups do not all have the same means, we can compare them two by two using the 2-sample t test. We need to adjust our p-value threshold because we are doing multiple tests with the same data. There are several methods for doing this. If we really just want to test the difference between one pair of treatments, we should set the study up that way.

Bonferroni method โ post hoc analysis
We reject null hypothesis if ๐ฅ ๐ผ โ ๐ฅ ๐ฝ โฅ ๐ก ๐โ๐ 1โ ๐ผ โ ๐๐ ๐ ๐ ๐ผ ๐ ๐ฝ , where ๐ผ โ is correct significance level, ๐ผ โ = ๐ผ ๐ 2 , ๐ก 1โ ๐ผ โ 2 ๐โ๐ is 1โ ๐ผ โ 2 is quantile of Student distribution with ๐โ๐ degrees of freedom.

Kruskal-Wallis test The KruskalโWallis test is most commonly used when there is one nominal variable and one measurement variable, and the measurement variable does not meet the normality assumption of an ANOVA. It is the non-parametric analogue of a one-way ANOVA.

Kruskal-Wallis test Like most non-parametric tests, it is performed on ranked data, so the measurement observations are converted to their ranks in the overall data set: the smallest value gets a rank of 1, the next smallest gets a rank of 2, and so on. The loss of information involved in substituting ranks for the original values can make this a less powerful test than an anova, so the anova should be used if the data meet the assumptions. If the original data set actually consists of one nominal variable and one ranked variable, you cannot do an anova and must use the KruskalโWallis test.

The farm bred three breeds of rabbits. An attempt was made (rabbits
The farm bred three breeds of rabbits. An attempt was made (rabbits.xls), whose objective was to determine whether there is statistically significant (conclusive) the difference in weight between breeds of rabbits. Verify.

The effects of three drugs on blood clotting was determined
The effects of three drugs on blood clotting was determined. Among other indicators was determined the thrombin time. Information about the 45 monitored patients are recorded in the file thrombin.xls. Does the magnitude of thrombin time depend on the used preparation?

Study materials : (p p.154) Shapiro, S.S., Wilk, M.B. An Analysis of Variance Test for Normality (Complete Samples). Biometrika. 1965, roฤ. 52, ฤ. 3/4, s Dostupnรฉ z: