Introduction

Aims

In this practical you will learn how to run, in R, a two-way ANOVA, interpret the output and report the results including figures. You will also learn how you can read data from a different file format.

Learning Outcomes

By actively following the lecture and practical and carrying out the independent study the successful student will be able to:

  • Explain the rationale behind ANOVA and complete a partially filled ANOVA table (MLO 1 and 4)
  • Read in data formatted for other statistical packages (MLO 3)
  • Apply (appropriately), interpret and evaluate the legitimacy of, two-way ANOVA in R (MLO 2, 3 and 4)
  • Explain the meaning of a significant interaction (MLO 4)
  • Summarise and illustrate with appropriate figures test results scientifically (MLO 3 and 4)
  • Use RStudio projects (MLO 4)

Philosophy

Workshops are not a test. It is expected that you often don’t know how to start, make a lot of mistakes and need help. Do not be put off and don’t let what you can not do interfere with what you can do. You will benefit from collaborating with others and/or discussing your results.

The lectures and the workshops are closely integrated and it is expected that you are familar with the lecture content before the workshop. You need not understand every detail as the workshop should build and consolidate your understanding. You may wish to refer to the slides as you work through the workshop schedule.

Slides

Two-way ANOVA: pdf (recommended) / pptx

Exercises

W Start RStudio from the Start menu.

Using RStudio projects

An RStudio project is associated with a directory (folder).

You create a new project with File | New Project…

When a new project is created RStudio:

  1. Creates a project file (with an .Rproj extension) within the project directory. This file contains various project options.
  2. Creates a hidden directory (named .Rproj.user) where project-specific temporary files (e.g. auto-saved source documents, window-state, etc.) are stored.
  3. Loads the project into RStudio and display its name in the Projects toolbar (far right on the menu bar).

Using a project helps you manage file paths. The working directory is the project directory (i.e., the location of the .Rproj file).

You can open a project with:

  1. File | Open Project or File | Recent Projects
  2. Double-clicking the .Rproj file
  3. Using the option on the far right of the tool bar

When you open project, a new R session starts and various settings are restored to their condition when the project was closed.

We are going to create an RStudio project to carry out the analysis of the Periwinkle data(below).

R Make a new project with File | New Project and chose New directory and then New project. Be purposeful about where you create it by using the Browse button. I suggest using your 17C folder. Give the Project (directory) a name, perhaps “periwinkle_workshop7”

R Make a new folder ‘raw_data’ where you will later save the original data file.

R Make a new folder ‘processed_data’ where you will later save the processed data file.

R Make a new folder ‘figures’ where you will later save your figures.

Reading Chapter 2 Project-oriented workflow of What they forgot to teach you about R (Bryan and Hester, n.d.).

R Make a new script file called workshop7.R to carry out the rest of the work.

Load packages

R You probably want to load the tidyverse with library(tidyverse).

Parasites on two species of periwinkle

This example is about the effect of season on the parasite load of two species of periwinkle.