L4 Anova - 082842
L4 Anova - 082842
An analysis of variance (ANOVA) tests whether statistically significant differences exist between more than two samples.
For this purpose, the means and variances of the respective groups are compared with each other.In contrast to the t-
test, which tests whether there is a difference between two samples, the ANOVA tests whether there is a difference
between more than two groups.
There are different types of analysis of variance, being the one-way and two way analyses of variance the most common
ones, each of which can be calculated either with or without repeated measurements. In this tutorial you will learn the
basics of ANOVA; for each of the four types of analysis of variance you will find a separate detailed tutorial:
• One-factor (or one-way) ANOVA
• Two-factors (or two-way) ANOVA
• One-factor ANOVA with repeated measurements
• Two-factors ANOVA with repeated measurements
# One-factor ANOVA
The one-way analysis of variance is an extension of the t-test for independent groups. With the t-test only a maximum of
two groups can be compared; this is now extended to more than two groups. For two groups (k = 2), the analysis
of variance is therefore equivalent to the t-test. The independent variable is accordingly a nominally scaled variable with
at least two characteristic values.
The dependent variable is on a metric scale. In the case of the analysis of variance, the independent variable is referred
to as the factor.The following question can be answered: Is there a difference in the population between the different
groups of the independent variable with respect to the dependent variable?
The aim of ANOVA is to explain as much variance as possible in the dependent variable by dividing it into the groups. Let
us consider the following example.
Variation
Variation is the sum of the squares of the deviations between a value and the mean of the value
Sum of Squares is abbreviated by SS and often followed by a variable in parentheses such as SS(B) or SS(W) so we know
which sum of squares we’re talking about
1- Are all of the values identical?
No, so there is some variation in the data
This is called the total variation
Denoted SS(Total) for the total Sum of Squares (variation)
Sum of Squares is another name for variation
2- Are all of the sample means identical?
• No, so there is some variation between the groups
• This is called the between group variation
• Sometimes called the variation due to the factor
• Denoted SS(B) for Sum of Squares (variation) Between the groups
3- Are each of the values within each group identical?
• No, there is some variation within the groups
• This is called the within group variation
• Sometimes called the error variation
• Denoted SS(W) for Sum of Squares (variation) Within the groups
• There are two sources of variation
• the variation between the groups, SS(B), or the variation due to the factor
• the variation within the groups, SS(W), or the variation that can’t be explained by the factor so it’s called
the error variation
Degrees of Freedom, df
A degree of freedom occurs for each value that can vary before the rest of the values are predetermined.
For example, if you had six numbers that had an average of 40, you would know that the total had to be 240. Five of the
six numbers could be anything, but once the first five are known, the last one is fixed so the sum is 240.
The df would be 6-1=5
The df is often one less than the number of values
• The between group df is one less than the number of groups
• We have three groups, so df(B) = 2
• The within group df is the sum of the individual df’s of each group
• The sample sizes are 7, 9, and 8
• df(W) = 6 + 8 + 7 = 21
• The total df is one less than the sample size
• df(Total) = 24 – 1 = 23
Variances
The variances are also called the Mean of the Squares and abbreviated by MS, often with convoying variable MS(B) or
MS(W)
They are an average squared deviation from the mean and are found by dividing the variation by the degrees of freedom
MS = SS / df
• MS(B) = 1902 / 2 = 951.0
• MS(W) = 3386 / 21 = 161.2
• MS(T) = 5288 / 23 = 229.9
F test statistic
An F test statistic is the ratio of two sample variances
The MS(B) and MS(W) are two sample variances and that’s what we divide to find F.
F = MS(B) / MS(W)
For our data, F = 951.0 / 161.2 = 5.9
The F test is a right tail test
The F test statistic has an F distribution with df(B) numerator df and df(W) denominator df
Here df of numerator =2
df of denominator =21
Now at 0.05 significant value
From table (F0.o5,2,21 = 3.4668)
• Since the calculated F (5.9) > Tabulated F(3.4668) ,so we reject the null
hypothesis.
• The null hypothesis is that the means of the three rows were the same, but we
reject that, so at least one row has a different mean.
• There is enough evidence to support the that there is a difference in the mean
scores of the front, middle, and back rows.
• The ANOVA doesn’t tell which row is different, you would need to look at
confidence intervals or run post hoc tests to determine that
# Welch's ANOVA
If the condition of variance homogeneity is not fulfilled, Welch's ANOVA can be calculated instead of the "normal" ANOVA.
If the Levene test results in a significant deviation of the variances in the groups, DATAtab automatically calculates the
Welch's ANOVA in addition.
Now we come to the assumptions of ANOVA with repeated measures and finally I will show you how you can easily
calculate it online. So what are the assumptions?
• Dependent samples: The samples must be dependent samples.
• Normality: The data should be approximately normally distributed and have metric scale level. This assumption is
especially important when the sample size is small. When the sample size is large, ANOVA is
somewhat robust to violations of normality.
• Sphericity: The variances of the differences between all combinations of factor levels (time points) should be the same.
• Homogeneity of Variances: The variance in each group should be equal. Levene's test can be used to check this
assumption.
• Homogeneity of Covariances (Sphericity): The variances of the differences between all combinations of the different
groups should be equal. This assumption can be tested using Mauchly's test of
sphericity.
• No significant Outliers: Outliers can have a disproportionate effect on ANOVA, potentially leading to misleading results.
Whether data is normally distributed or not can be tested using the QQ plot or the Kolmogorov smirnov test.
Whether the assumption of sphericity is violated can be tested using Mauchly's test for sphericity. If the resulting p-value
is greater than 0.05, it can be assumed that the variances are equal, and the condition is not violated.
If this assumption is violated, adjustments such as Greenhouse-Geisser or Huynh-Feldt can be made.
The analysis of variance with repeated measurement gives you a p-value for your data. With the help of this p-value you
can read whether there is a significant difference between the repeated measurements.
If the calculated p-value is smaller than the predefined significance level, which is usually 0.05, the null hypothesis is
rejected.
In this example, the p-value is 0.01, which is less than 0.05. Therefore, the null hypothesis is rejected and it can be assumed
that there is a difference between the different time points.
#The Post-hoc-Test
As soon as there is a significant difference between the different time points, it is of course also of interest to identify
between which exact time points that difference exists. This can be found out with the help of the Bonferroni post
hoc test.
In the post-hoc test in a repeated measures ANOVA, multiple t tests are calculated for dependent samples. However, the
problem with multiple testing is that the so-called alpha error (the false rejection of the null hypothesis) increases with
the number of tests. To counteract this, the Bonferroni post-hoc test calculates the obtained p-values times the number
of tests.
In the present case, 3 tests were performed, so for the calcula on of the post-hoc test, the p-value obtained from the t-
test was multiplied by 3 in the background. If one or more p-values are less than 0.05, a significant difference between
the two groups is assumed. In this case, we therefore have a significant difference between Before and End and between
Middle and End.
# Calculate a repeated measures ANOVA
How do you calculate an analysis of variance with repeated measures by
hand? Here you can find the formulas to calculate an ANOVA.
Let's say this is our data. We have 8 people, each of whom we measured at
three different points in time (start, middle and end).
First, we can calculate the necessary mean values. With the mean values we can calculate the Sum of squares and the
Mean Square. Now we can calculate the F value, which is calculated by dividing the mean square of the treatment by the
mean square of the residual or error.
Finally we can calculate the p value using the F value and the degrees of freedom from the treatment and error. To
calculate the p-Value we use the F distribution.
Now in all three cases you would not have one factor, but two factors each.And since you now have two factors, you use
the two-way analysis of variance.
Using the two-way analysis of variance, you can now answer three things:
• Does factor 1 have an effect on the dependent variable?
• Does factor 2 have an effect on the dependent variable?
• Is there an interac on between factor 1 and factor 2?
Therefore, in the case of one-way analysis of variance, we have one factor from which we create the groups. In the case
of two-way analysis of variance, the groups result from the combination of the expressions of the two factors.
After all, is attitude toward retirement planning really a metric variable? Let's just assume that attitude toward retirement
planning was measured using a Likert scale and thus we consider the resulting variable to be metric.
Mean values
In the first step we calculate the mean values of the individual groups, i.e. of male and not studied, which is 5.8 then of
male and studied, which is 5.4, we now do the same for female.
Then we calculate the mean of all male and female and of not studied and studied respectively. Finally, we calculate the
overall mean as 5.4.
Sums of squares
With this, we can now calculate the required sums of squares. SStot is the sum of squares of each individual value minus
the overall mean.
SSbtw results from the sum of squares of the group means minus the overall mean multiplied by the number of values in
the groups.
The sums of squares of the factors SSA and SSB result from the sum of squares of the means of the factor levels minus the
total mean.
Now we can calculate the sum of squares for the interaction. These are obtained by calculating SSbtw minus SSA minus
SSB.
Finally, we calculate the sum of squares for the error. This will calculate similar to the total sum of squares, so again we
use each individual value. Only in this case, instead of subtracting the overall mean from each value, we subtract
the respective group mean from each value.
Degrees of freedom
The required degrees of freedom are as follows:
p-value
This gives us a p-value of 0.323 for Factor A, a p-value of 0.686 for Factor B, and a p-value of 0.55 for the interac on. None
of these p-values is less than 0.05 and thus we retain the respective null hypotheses.
#Interaction effect
But what exactly does interaction mean? Let us first have a look at this diagram.
The dependent variable is plotted on the y axis, in our example the attitude towards retirement provision. On the x axis,
one of the two factors is plotted, let's just take gender. The other factor is represented by lines with different
colors. Green is studied and red is not studied.
The endpoints of the lines are the mean values of the groups, e.g. male and not studied. In this diagram, one can see that
both gender and the variable of having studied or not have an influence on attitudes toward retirement planning. Females
have a higher value than males and studied have a higher value than not studied. But now finally to the interaction effects,
for that we compare these two graphs.
In the first case, we said there is no interaction effect. If a person has studied, he has a value that is, say, 1.5 higher than
a person who has not studied. This increase of 1.5 is independent of whether the person is male or female.
It is different in this case, here studied persons also have a higher value, but how much higher the value is depends on
whether one is male or female. If I am male, there is a difference of, let's say for example 0.5 and if I am female,
there is a difference of 3.5.
So in this case we clearly have an interaction between gender and study because the two variables affect each other. It
makes a difference how strong the influence from studying is depending on whether I am male or female.
In this case, we do have an interaction effect, but the direction still remains the same. So females have higher scores than
males and studied have higher scores than non-studied.
You may want to know if the treatment for high blood pressure has an effect on the blood pressure. So you want to know
if blood pressure changes over time.
But what if you have different therapies and you want to see if there is a difference between them? You now have two
factors, one for the therapy and one for the repeated measurements. Since you now have two factors and one
of the factors is a dependent sample, you use a two-way repeated measures
analysis of variance.
Using two-way analysis of variance with repeated measures, you can now answer three things:
• Does the first factor with measurement repetition have an effect on the dependent variable?
• Does the second factor have an effect on the dependent variable?
• Is there an interac on between factor 1 and factor 2?
Hypotheses
As already indicated, you can test three statements with the 2 factorial analysis of variance, so there are also 3 null
hypotheses and therefore also 3 alternative hypotheses.
Null hypotheses:
• The mean values of the different measurement times do not differ (There are no significant differences between the
"groups" of the first factor).
• The mean values of the different groups of the second factor do not differ.
• One factor has no influence on the effect of the other factor