Two-way Anova (2)

To conduct a two-way Anova, we can use the exact same functions as when conducting a one-way Anova. This means that both the aov() and lm() functions will work out. When doing a two-way anova, our between-group variance is split across both groups. This essentially means that our first variable will explain a certain amount of variance and our second variable will explain a certain amount of variance.

You can use the aov() with multiple independent variables like so:

aov(dependent_variable ~ independent_variable1 + independent_variable2)

You just have to replace independent_variable1 and independent_variable2 by the names of the variables that you are working with.

This exercise is part of the course

Inferential Statistics

View Course

Exercise instructions

  • For the current exercise, all our data is available in the dataframe song_data. Conduct a two-way Anova using the aov() function. Note that you can add variables to your anova by putting a + sign behind your first independent variable followed by the name of the second independent variable. Add the anova model to the variable two_way_fit
  • Call the summary function on your your two_way_fit object and print the output to the console.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# run a two-way anove and store it in the object two_way_fit


# call the summary function on the object two_way_fit