A one-sample t-test is used to test if the mean of sample differs from a known or hypothesized population mean.
Example: I have a vector of heights in centimeters. I want to see whether the average height of vector is 165 cm.
heights <- c(162, 164, 167, 170, 160, 165, 163, 168, 172, 159, 190, 154, 204)
Set the hypothesis tests to be: - The mean height is 165 cm, this will be our \(H_0\) - The mean height is not 165 cm, this will be our \(H_a\) - Our alpha will be 0.05, or within a confidence range of 95% - We will reject the null hypothesis if the p value is greater than 0.05
Perform the t-test in R:
h_test_result <- t.test(heights, mu = 165)
print(h_test_result$p.value)
## [1] 0.3003206
As we can we see our p-value is 0.3003206, which is greater than the 0.05 that we set for our \(a\), therefore me must reject the null hypothesis Which means, that the mean of the heights is not 165 cm.