Student’s t-test (also known as Welch two sample test) requires that samples are independent, of equal variance and normally distributed. The Shapiro-Wilk test may thus be employed to check for normality prior to performing the comparison; Fisher’s F test will help checking for equal variances.
In Student’s t-test, the null hypothesis H0 states that the means of the two samples are equal.
In the following example, we’ll compare the samples
Let’s check these samples in a boxplot :
boxplot(W1.may15,W1.may16, ylab="Temperature (degrees Celsius)", names=c("W1.may15","W1.may16"))
As you may see, the samples and their medians appear to slightly differ, but the respective spreads of the samples seem similar. Let’s proceed with verifying the assumptions of normality and equal variance:
shapiro.test(W1.may15) shapiro.test(W1.may16) var.test(W1.may15, W1.may16)
According to the Shapiro-Wilk test, both samples are likely to come from normal distributions. Looking at Fisher’s F test, the variances of the groups are equal. All assumptions for running Student’s t-test are respected.
Satisfied? Let’s keep going then. Now it is (finally) time to perform Student’s t test:
The p-value that results from the test is greater than 0.05 (the typical value of α); therefore, the null hypothesis H0 (the means of temperature observed during the first week of May 2015 and during the first week of May 2016 are equal) cannot be rejected.