Presentation is loading. Please wait.

Presentation is loading. Please wait.

ANOVA (Analysis of Variance)

Similar presentations


Presentation on theme: "ANOVA (Analysis of Variance)"โ€” Presentation transcript:

1 ANOVA (Analysis of Variance)
Martina Litschmannovรก K210

2 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

3 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?

4 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

5 Side by Side Boxplots

6 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.

7 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

8 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.

9 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.

10 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.

11 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 ๐‘› ๐‘– ๐‘‹ ๐‘–๐‘— โˆ’ ๐‘‹ ๐‘–

12 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.

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

14 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

15 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.

16 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

17 How are these computations made?
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

18 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

19 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)

20 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

21 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

22 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

23 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

24 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

25 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 / = / =

26 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

27 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

28 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

29 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)

30 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.

31 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.

32 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.

33 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.

34 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.

35 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?

36 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:


Download ppt "ANOVA (Analysis of Variance)"

Similar presentations


Ads by Google