Professional Documents
Culture Documents
• Why ANOVA
• Assumptions used in ANOVA
• Various forms of ANOVA
• Simple ANOVA tables
• Interpretation of values in the table
• R commands for ANOVA
• Exercises
Why ANOVA: Examples
If we have two samples then under mild conditions we can use t-test to test if difference between
means is significant. When there are more than two sample then using t-test might become
unreliable.
ANalysis Of VAriances – ANOVA is designed to test differences between means in many
sample cases.
Examples of ANOVA: Suppose that we want to test effect of various exercises on weight loss.
We want to test 5 different exercises. We recruit 20 men and assign for each exercises four
of them. After few weeks we record weight loss. Let us denote i=1,2,3,4,5 as exercise
number and j=1,2,3,4 person’s number. Then Yij is weight loss for jth person on the ith
exercise programme. It is one-way balanced ANOVA. One way because we have only one
category (exercise programme). Balanced because we have exactly same number of men
on each exercise programme.
Another example: Now we want to subdivide each exercises into 4 subcategories. For each
subcategory of the exercise we recruit four men. We measure weight loss after few weeks
- Yijk. Where:
i – exercise category
j – exercise subcategory
k – kth men.
Then Yijk is weight loss for kth men in the jth subcategory of ith category. Number of
observations is 5x4x4 = 80. It is two-fold nested ANOVA.
We want to test: a) There is no significant differences between categories; b) there is no
significant difference between different subcategories. It is two-fold nested ANOVA
Examples of ANOVA
One more example: We have 5 categories of exercises and 4 categories of diets. We hire for each
exercise and category 4 persons. There will be 5x4x4=80 men. It is two way crossed
ANOVA. Two-way because we have categorised men in two ways: exercises and diets.
This model is also balanced: we have exactly same number of men for each exercise-diet.
i – exercise number
j – diet number
k – kth person
Yijk – kth person in the ith exercise and jth diet.
In this case we can have two different types of hypothesis testing. Assume that mean for each
exercise-diet combination is ij. If we assume that model is additive, i.e. effects of exercise
and diet add up then we have: ij = i+j. i is the effect of ith exercise and j is the effect
of diet. Then we want to test following hypotheses: a) ij does not depend on exercise and
b) ij does not depend on diet.
Sometimes we do not want to assume additivity. Then we want to test one more hypothesis:
model is additive. If model is not additive then there might be some problems of
interpretations with other hypotheses. In this case it might be useful to use transformation
to make the model additive.
Models used for ANOVA can be made more and more complicated. We can design three, four
ways crossed models or nested models. We can combine nested and crossed models
together. Number of possible ANOVA models is very large.
Design of Experiment
• Blocking
• Replication
Assumptions
ANOVA models are special cases of the linear models. We can write the model as:
Y = μ +ε
Where Y is the observation vector, -is a vector of the means composed of the treatment
means and is the error vector. Basic assumptions in ANOVA models are:
€
1. Expected values of the errors are 0
2. Variance of all errors are equal to each other
3. Errors are independent
4. Errors are normally distributed
All ANOVA treatments are very sensitive to assumptions 1)-3). F-tests meant to be robust
against the assumption 4). If assumptions 1)-3) are valid then 4) will always be valid at
least asymptotically. I.e. for large number of the observations.
ANOVA tables
Standard ANOVA tables look like
Then mean sum of the squares for the null and alternative hypotheses as:
σˆˆ 2 −σˆ 2
SSh = and for the alternative hypothesis
dfh
σˆ 2
SSe =
dfe
Since first sum of the squares is 2 with degrees of freedom dfh and the second sum of squares is
2 with degrees of freedom dfe and they are independent then their ratio has F-distribution
with degrees of freedom (dfh,dfe). Degrees of freedom of hypothesis is found using
number of elements in the category-1 in the simplest case.
Using this type of ANOVA tables we can only tell if there is significant differences between
means. It does not tell which one is significantly different.
This ratio has F distribution if null-hypothesis is true. Otherwise it has non-central F-distribution.
Degree of freedom of hypothesis is defined by number of constraints it implies. Degree of
freedom of error is as usual number of observations minus number of parameters
Example: Two way ANOVA
Let us consider an example taken from Box, Hunter and Hunter. Experiment was
done on animals. Survival times of the animals for various poisons and
treatment was tested. Table is:
treatment
A B C D
poisons
I 0.31 0.82 0.43 0.45
0.45 1.10 0.45 0.71
0.46 0.88 0.63 0.66
0.43 0.72 0.76 0.62
Now we can say that there is significant differences between poisons as well as treatments.
Sometimes it is wise to use transformation to reduce effect of interactions. For this several
different transformations (inverse, inverse square, log) could be used. For each of them
ANOVA tables could be built. Then by inspection you can decide which transformation
gives better results. Following argument could be used to justify transformation. If
effects of two different categories is multiplicative then log of them will have additive
effect. It is easier to interpret additive effects than others.
R commands for ANOVA
There are basically two type of commands in R. First is to fit general linear model and second is analyse
results.
Command to fit linear model is lm and is used
lm(data~formula)
Formula defines design matrix. See help for formula. For example for PlantGrowth data (available in R) we
can use
data(PlantGrowth) - load data into R from standard package
lmPlant = lm(PlantGrowth$weight~PlantGrowth$group)
Then linear model will be fitted into data and result will be stored in lmPlant
Now we can analyse them
anova(lmPlant) will give ANOVA table.
If there are more than one factor (category) then for two-way crossed we can use
lm(data~f1*f2) - It will fit complete model with interactions
lm(data~f1+f2) - It will fit only additive model
lm(data~f1+f1:f2) - It will fit f1 and interaction between f1 and f2. It is used for nested models.
Other useful commands for linear model and analysis are
summary(lmPlant) – give summary after fitting
plot(lmPlant) - plot several useful plots
Please let me know if any of the results is not clear then we can discuss and try sort out the problems.
R commands for ANOVA
This command gives confidence intervals for some of the coefficients and
therefore differences between effects of different factors.
To find confidence intervals between any two given effects one can use
bootstrap.
ANOVA with generalised linear model
If distribution of a data set is from one of the members of exponential family then the
command is
lm(data~formula,family=family)
Where family is one of the distributions from exponential family. These are
poisson, binomial, Gamma etc
And all other analysis are done using similar command like anova, summary etc.
Note that if you use glm then anova will give analysis of deviances instead of
analysis of variances and will not print probabilities by default. You need to
specify it. For example if you have used Poisson or binomial distributions then
you can use
anova(glmresult,test=‘Chisq)
Bootstrap for ANOVA
Algorithm for bootstrap: