Before you start :
- Create a folder / directory on your PC where you put all files related to this practical
- Turn this folder into your working directory
setwd ( "C:/wherever your files are")
1. Demo : the independent sample t-test
Data in long format : ozoneLong.txt
Read in the dataset ozoneLong.txt. This small dataset contains measurements of ozone (O3) in
two gardens, labelled A and B.
First explore the data :
- How are the data organized? Check the environment in RStudio, or the str() function.
What do the two variables mean?
- Generate a plot to visualize the ozone concentration in the two gardens
Research question is whether the mean O3 concentration differs between the two gardens.
The most common parametric and non-parametric tests to test this hypothesis are the
independent sample t-test and the Mann-Withney U test, respectively.
Check out the help function for the independent samples t-test in R. With the data in long
format, the most convenient way to carry out the t-test is using the formula interface.
?t.test
Carry out the t-test on the ozoneLong.txt dataset. Interpret the output on the screen :
- Is there a significant difference in mean O3 value between the two gardens
- What is the 95% confidence interval of the difference?
- Yes, because the p-value is less than 0.05 (= 0.001114539)
- [-3.0849115, -0.9150885]
To extract separate elements of the output, store the results of your t-test into an object
myResult <- t.test (… whatever code you used… )
The names() function tells you which elements can be extracted from this results-object
names(myResult)
Use the $ operator to extract the following elements from the results object :
- P-value
- 95% confidence interval of the difference
1