In this practical you will get practice in choosing between, performing, and presenting the results of one- and two- sample t-tests and their non-parametric equivalants in R.

Learning Outcomes

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

  • Explain the difference between dependent and independent samples (MLO 2)
  • Select, appropriately, t-tests and their non-parametric equivalents (the Wilcoxon tests) (MLO 2)
  • Apply, interpret and evaluate the legitimacy of the tests in R (MLO 3 and 4)
  • Summarise and illustrate with appropriate R figures test results scientifically (MLO 3 and 4)


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.


There are two lectures for this work shop.

One-sample tests: pdf (recommended) / pptx

Two-sample tests: pdf (recommended) / pptx


Getting started

W Start RStudio from the Start menu.

R In RStudio, set your working directory to the folder you created previously for your 17C Data Analysis work.

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

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

Egg laying in parasitic wasps

The data in wasp.txt concern the egg-laying behaviour of a species of parasitic wasp, laying its eggs on a beetle larva. Wasps and other Hymenopterans (Ants and Bees) are haplo-diplod: unfertilised eggs are haploid and develop into males, whereas fertilised eggs are diploid and develop into females. Researchers wanted to know if mating status affected the time (in hours) the wasp takes to lay its eggs. Each row represents an individual wasp. The first column gives the time taken and the second column indicates whether they are mated or unmated.

W Save a copy of the data file wasp.txt

R Read in the data and check the structure

R Do a quick plot of the data: