Consider our example again. Suppose that \(n = 16\) (rather than \(100\))
The test statistic
\[ \frac{\bar{X} - 30}{s/\sqrt{16}} \]
follows a \(t\) distribution with \(15\) \(df\) under \(H_0\) : \(\mu = 30\)
Under \(H_0\), the probability that it is larger than the \(95th\) percentile of the \(T\) distribution is \(5%\)
The \(95th\) percentile of the T distribution with 15 \(df\) is \(1.7531\) (obtained via the R command qt(.95, 15))
So that our test statistic is now \(\sqrt{16}(32 - 30)/10 = 0.8\)
We now fail to reject because \(0.8\) is smaller than \(1.7531\)
This doesn’t make a lot of sense in our specific scientific setting, because we’re specifically interested in whether or not this particular population of obese subjects had a respiratory disturbance index, larger than 30 or reference value.
However it’s often the case that in scientific settings, a two-sided test is demanded, regardless of whether or not it makes scientific sense. So it’s important to understand how to do two-sided tests, and the fact that there are some instances where you are mandated to deal with two-sided tests, even though it doesn’t necessarily make that much sense to consider the other side.
We want to test the alternative \(H_a\) : \(\mu \ne 30\)
We will reject if the test statistic, \(0.8\), is either too large or too small
In this case because the test statistic is positive, we only need to consider the large side.
Then we want the probability of rejecting under the null hypothesis to be \(5\%\), split equally as \(2.5\%\) in the upper tail and \(2.5\%\) in the lower tail
Thus we reject if our test statistic is larger than qt(.975, 15) or smaller than qt(.025, 15)
However, because the lower quantile is negative of the positive quantile, we can always say that’s the same thing as taking the absolute value of our test statistic and rejecting if it’s too large.
* This is the same as saying: reject if the absolute value of our statistic is larger than `qt(0.975, 15) = 2.1314`
And now in this slide we’re showing that we failed to reject the two sided test.
* So we fail to reject the two sided test as well
However, because we’ve moved further out into the tails of \(t\) distribution with our rejection region, that if you fail to reject the one sided test then you will also have failed to reject the two sided test.
* (If you fail to reject the one sided test, you know that you will fail to reject the two sided)
Usually we don’t calculate the rejection region and perform the rejection region and perform the hypothesis test in the formal manner in which we’ve gone through in the slides by hand, instead, we usually pass the data to a function like t.test, and it outputs all the relevant statistics for us, to understand what’s going on with the test. What’s interesting is we already know how to do this, because we’ve used t.test in order to perform confidence intervals. We just haven’t gone through the output to understand what it’s doing for a test.
Let’s look at, in the UsingR package, the data father.son. We’d like to test whether the population of son’s height was equivalent to the population mean of father’s heights.
library(UsingR); data(father.son)
## Loading required package: MASS
## Loading required package: HistData
## Loading required package: Hmisc
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
##
##
## Attaching package: 'UsingR'
##
## The following object is masked from 'package:ggplot2':
##
## movies
##
## The following object is masked from 'package:survival':
##
## cancer
t.test(father.son$sheight - father.son$fheight)
##
## One Sample t-test
##
## data: father.son$sheight - father.son$fheight
## t = 11.789, df = 1077, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 0.8310296 1.1629160
## sample estimates:
## mean of x
## 0.9969728
The observations here were paired, it was one son’s measurement to one father’s measurement, and so on. So it’s in this case we’re going to take the difference and we want to test whether the difference in the heights is \(0\) or is non zero. We do that t.test and you can either pass the difference directly to the function t.test, or you can pass the two vectors, and then add the argument paired = TRUE. It gives you your \(t\) statistic \(11.79\). It gives you your degrees of freedom \(1,077\). So we had exactly \(1,078\) pairs that we took the difference of. \(11\) is a quite large \(t\) statistic, so we reject the null hypothesis in this case. Also notice that the degrees of freedom are quite large so the distinction between a t-test and a z-test in this case is irrelevant. It very nicely gives us the \(t\) confidence interval, automatically when we do t.test. It’s useful almost always to look at the confidence interval in addition to the output of the test. Simply because the confidence interval bridges the gap between statistical significance and practical significance quite nicely. You can see whether the range of values in the confidence interval are of practical significance or not, because it’s expressed in the units of the data you’re interested in.