2024-02-03

Why Hypothesis Testing?

Researchers are often interested in answering questions about entire populations, but for one reason or another data cannot be collected from the whole population and only sample data is available.

This is where hypothesis testing comes in. It allows us to make inferences about a population using sample data.

How Does Hypothesis Testing Work?

Hypothesis testing compares a sample to a given population in order to determine whether there is a significant difference between the two.

  • Null Hypothesis (H0): states that there is no difference
  • Alternative Hypothesis (H1): states there is a difference

The goal of hypothesis testing is to accept or reject the null hypothesis.

Mathematical Notation

The null hypothesis and alternative hypothesis are often represented mathematically.

For example, does a class taught using a new method have a higher GPA than classes taught using the old method?

  • Null Hypothesis:   \(H_0: \mu_1 \leq \mu_2\)
  • Alternative Hypothesis:   \(H_1: \mu_1 > \mu_2\)

If you wanted to know whether there was a difference in either direction you would represent that mathematically like so:

  • Null Hypothesis:   \(H_0: \mu_1 = \mu_2\)
  • Alternative Hypothesis:   \(H_1: \mu_1 \neq \mu_2\)

Testing the Null Hypothesis

If a sample is randomly drawn, it should contain more of the values that are common in the population and fewer of the values that are less common in the population. Using this idea of probability, we can determine how likely it is that our sample comes from a given population.

This means we can reject the null hypothesis (which states that there is no difference) if our sample is unlikely to come from the given population, suggesting they are in fact different.

There are many statistical tests that can be used to test a hypothesis. One example is the z test, which uses the formula:

\[ z = \frac{\bar{x} - \mu} {\frac{\sigma} {\sqrt{n}}} \]

Rejecting the Null Hypothesis

In order to reject a null hypothesis of no difference, our sample would need to fall within one of the critical regions on either end of the population distribution where scores are least likely to appear.

Rejecting a Directional Null Hypothesis

Rejecting a directional null hypothesis works the same way except that the critical region is now located entirely in one end, or tail, of the distribution.

Normal Distribution Code

The base for the normal distribution in the previous plot was created using the following code:

library(ggplot2)

data = data.frame(x = c(-3, 3))
ggplot(data.frame(data), aes(x)) +
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1), 
                color = "steelblue", linewidth = 1) + 
  ggtitle("Normal Distribution") + 
  xlab("Standard Deviations") + ylab("") +
  scale_x_continuous(breaks = seq(-4, 4, 1)) + 
  theme(axis.text.y = element_blank(), axis.ticks.y = element_blank(),
        plot.title = element_text(hjust = 0.5))

Distributions in the real world won’t always be this perfectly normal, but the concepts here still apply.

Multivariate Hypothesis Testing

Hypothesis testing can even be used to answer more complicated research questions, such as those involving multivariate statistics. Complicated relationships like this can be represented in the form of 3D plots like below.