How do you design a hypothesis test?
Let’s pretend that you are a researcher looking at the effects of a particular drug on blood pressure. You have a suspicion that it has an unintended effect on blood pressure (but you aren’t sure if it raises blood pressure or lowers it).
You’ve run a trial, and have collected some data. The data is a collection of numbers, where each number represents the change in blood pressure of a particular trial participant before and after taking the drug. You reason that if the drug really does have an effect, then the numbers should either all tend to be positive (increase in pressure) or tend to be negative (decrease in pressure). If there is no overall effect, then the numbers should be centred around zero.
You look at your data, and see that some numbers are positive and some are negative, but you are not sure if you see an overall trend. How can you take your data, and quantitatively test your belief on whether the drug has any effect on the blood pressure at all? This is the job of a hypothesis test.
Well, how does one design a hypothesis test when you have questions like this? In this article, I’ll give you a taste of the process by walking through what you might do for our made-up scenario above.
1. Give a form to the generative distribution
The first step in mathematically formalising our question into a hypothesis test is to make some assumptions (educated guesses!) about the underlying probability distribution generating your data. As a way to do this, let’s start to talk about our data and distributions using mathematical symbols.
Let’s say that we have data points. We’ll call them . We can imagine that our data is actually a sample from some unknown generative distribution . The thinking is that if we can somehow manage to characterise , we might glean some insights into the actual process that generated the data (i.e. whether there seems to be a real change in blood pressure).
Where can we start? Well, since our data points are continuous variables resulting from complex biological processes, it might be reasonable to assume that the data is likely distributed according to a normal distribution. If is a normal distribution, it can be described by two parameters: its mean and variance. To make our lives simple, let’s assume the true population variance is already known to us (perhaps from extensive prior biological studies on this drug). That leaves us with one free parameter, the mean, to play around with. We will assign the symbol to the mean parameter, so that the probability density function can be written as:
Now we can start to discuss our hypothesis test in a more precise language. We think that our data comes from a normal distribution like . We also think that if the drug really causes increases in blood pressure, our data should be centered around a positive value, which means that should be positive, and vice versa () if there is a reduction in blood pressure. If there is no effect, then we would expect . As you can see, our hypothesis test is linked to our belief of what the true value of is. More specifically, our null hypothesis (conventionally denoted ) is that there is no effect, or that , and our alternative hypothesis (denoted ) is that there is some effect (either up or down), or that .
More formally, we would say that is a parametric distribution with one unknown parameter . We can then think of as being a member of a family of distributions , where can be anything. We then split the parameter space into two parts: the null parameter space , and its complement . consists of values of corresponding to the null hypothesis, whereas corresponds to the alternative hypothesis, and thus usually contains more interesting values of . That is, the null hypothesis can now be written as , and the alternative hypothesis as , or .
To bring it back to our concrete example, our parameter is a real number, so , and .
Now that we have a mathematical framework for our hypotheses, how can we test our belief on whether the true lies inside or , based on the data ?
2. Pick a hypothesis testing framework
We need a system where we can use the available data to compute some statistic, then depending on the value of the statistic, either reject or not. There are many strategies/frameworks with which one can come up with a test statistic1, but for this example let’s use the very common and useful likelihood ratio test (LRT). The LRT involves a test statistic of the form:
Here, signifies the likelihood function. LRTs have a rejection region (here is the space of all possible set of data points) of the form: with some constant.
What is the constant in the definition of the rejection region? What does it mean, and how do we pick it? Good questions- we will come back to this in a later step below where we pick the desired “size” of our test.
The basic intuition of the LRT is that you are comparing how likely your data would be if had to be inside , versus if were allowed to be anything it wanted. If contains areas of parameter space that could very well explain , then the numerator will be almost or exactly as big as the denominator. This means will be relatively large and you won’t be able to reject . In contrast, let’s say that no in is very likely to produce . Then might get quite small, and if it is small enough () you can reject .
3. Apply the framework to the problem at hand
Now that we know what the LRT is, and have built some intuition around it, we need to apply it to our problem. Our mystery distribution takes the form of a univariate normal with mean . So in our case, what is ?
Well, in general we know that . Thus, in our case (remember that is a set of samples):
So now we can express . We next need to figure out what and are. In our case, the numerator of is trivial, since and thus .
For , we need to do a bit of optimisation work as shown below, since is not a singleton set. For a bit of terminology, the we are looking for here where the likelihood function is maximised, is called the maximum likelihood estimate (MLE) of given .
To work out the MLE of for a univariate normal, we can set .
Since can never equal zero,
As such the MLE for here is the arithmetic average over , denoted here as . Therefore, .
Putting all of this together, you get:
We can now identify the rejection region within our sample space as:
4. Pick a size for your test
Where are we now? Well, we have a well-defined test statistic that in our case partitioned the sample space into rejection region and its complement. But you might notice that the exact boundaries of our rejection region still depends on a variable that we so far have not yet set explicitly: . Earlier I promised that we would discuss what means and how we pick it. We will do so here.
In statistics, a useful way to categorise the calibre of hypothesis tests is by reporting its “size”, or sometimes “level”. The intuition behind the meaning of a test with size is a test where, if were true (the value of were to lie inside of ), the maximum probability of a type 1 error (wrongly rejecting the null hypothesis) is .
What is meant by the “maximum probability”? Well, remember that can contain many different possible values for . Some values of within may produce distributions that look nothing like ones that could arise if . If the true were to be such a value, then there is a good chance that the data also looks decisively “null-like”. In situations like that, the probability of wrongly rejecting should be very small. Now imagine picking a out of such that you pick the that most closely resembles a outside of . Maybe this sits right on the boundary between and . If this was the true value for , then unless you have a lot of data, the evidence might sometimes accidentally look like it comes from a distribution with , simply due to chance. Therefore, the probability of a type 1 error should be higher. In a size test, the probability of a type 1 error in the worst case scenario- where the true is the one that most looks like a non-null - is equal to . That’s what I meant by the “maximum probability” of a type 1 error.
The more succinct and technical definition would be that a hypothesis test of size is a hypothesis test whose power function has a maximum value of when evaluated within .
If you have worked in biology or medicine, you often hear about data showing “statistical significance” with a “ value less than 0.05”. You may also remember being taught the meaning of a value being less than 0.05. That is, if there is no real signal (e.g. no real difference between two groups of data), then the probability of seeing a signal as large as or larger than what the data shows is less than 0.05. Well, now that you’ve been introduced to some statistics jargon, you can equivalently say that such hypothesis tests have a size or level () of 0.05. Another way of thinking about this is that is basically a threshold such that if the value is less than , you reject the null hypothesis.
With this in mind, let’s say that we want our hypothesis test to be of size 0.05. That is, a maximum type 1 error probability of 5%. We can calibrate our threshold such that if , the maximum probability that the data is 5%.
In our case, only contains 0, so there is no need to do any optimisation.
Since (the sample mean of normal random variables is normal), and :
Where . Now we want this probability to be 0.05, or . Let denote the critical point such that . Then:
Et voila! We now have our threshold , calibrated so that our test is of size 0.05. Armed with this , all you have left to do is to check whether the following is true:
If yes, then according to our test design and assumptions, you can reject . If not, then you cannot reject .
The LRT framework chosen for this article is an example of a frequentist test framework. Other examples of frequentist frameworks include the Wald test and score test. Of course, there is an entire world of Bayesian inference out there as well, but this is all a bit outside the scope of this article. ↩︎