10  Analysis Of Variance (ANOVA)

Before we dive into a new test, let us take a second to look back at the tests we have already covered and remember what those tests allowed us to do, and what the data for those tests looked like:

Z-Test

T-Test

Why is ANOVA different?

Here is what t-test for independent samples might look like:


You will notice that there are two columns, one for a condition of control and one for a condition of experimental.

We we have yet to discuss what this experiment actually is trying to answer, but, we can tell from looking at the data that whatever experimental isβ€”it’s mean is higher than control and may be a significant difference.

Here is what an ANOVA might look like:


As you can see, we still have two columns, but the main difference is that what used to be a condition two separate samples has become one single sample, separated by the various conditions.

Herein lies the main difference between t-tests and ANOVAs: the amount of conditions (levels) that can be compared.

t-tests can only compare two levels, while ANOVAs can compare more than two levels.

There are several notes to make when dealing with data in the format of an ANOVA.

It becomes essential that you understand the differences between an independent variable and a dependent variable.

When you are dealing with 3 or more conditions, you need to convert them into factors if they are not already.

factors are a type of data that tell R which subjects are in which condition.

You can check if a vector is a factor by running the is.factor() function.

We we will go through some examples to see what it looks like when R recognizes a vector as a factor and when it does not.

The following example shows a vector of conditions. However, R does not know that these are conditions until we tell it that they are factors. If we are unsure if R knows if a vector is a factor, we can test it using is.factor :


Now that we know that R does not consider this vector to be a factor, we can manually tell R to make it a factor.


Now R, will recognize example as a factor.