2024-03-16

Hypothesis Test

Hypothesis testing procedures depend on the point estimates \(\bigl(\bar{x}, s\) or \(s^2, \hat{p}\;\bigr)\) from a random sample of size \(n\). Let us define the following:

  • \(H_0\) is our null hypothesis.

  • \(H_a\) is our alternative hypothesis. For the sake of this presentation, we will consider \(\neq, <, or >\).

We will compute a test statistic using the point estimate. If the test statistic indicates we do not have evidence to favor the alternative hypothesis, then we will fail to reject the null hypothesis. However, if there is evidence in favor of \(H_a\) then will we reject \(H_0\).

For the sake of this presentation, we will be focusing on a hypothesis test on the population mean \((\mu)\), with population variance \((\sigma^2)\) known.

Types of Hypothesis Tests

Let \(\theta\) represent the population parameter we are interested in testing.

  • Two-Sided Test

    \(H_0 : \theta = \theta_0 \hspace{2cm} H_1: \theta \neq \theta_0\)

  • One-Sided Test (Upper)

    \(H_0 : \theta = \theta_0 \hspace{2cm} H_1: \theta > \theta_0\)

  • One-Sided Test (Lower)

    \(H_0 : \theta = \theta_0 \hspace{2cm} H_1: \theta < \theta_0\)

Hypothesis Test General Procedure

  1. Identify the population parameter of interest

  2. Formulate the null hypothesis \(H_0\)

  3. Determine whether the problem is two-sided, one-sided upper, or one-sided lower, and use this information to formulate the alternate hypothesis \(H_a\)

  4. Choose significance level \(\alpha\)

  5. Determine the rejection criteria (critical values for test statistic)

  6. Compute the appropriate test statistic

  7. Draw appropriate conclusions and interpret your results

Hypothesis Test on \(\mu\), \(\sigma^2\) Known

Let \(z_0\) denote the test statistic. We can compute it as follows:

\(z_0 = \dfrac{\bar{x}-\mu_0}{\sigma/\sqrt{n}}\)

where \(\bar{x}\) is the sample mean, \(\mu_0\) is the mean given by the null hypothesis, \(\sigma\) is the known standard deviation, and \(n\) is the sample size.

The given parameter \(\alpha\) represents our chosen significance level.

The values for \(\pm z_{\alpha}\) can be calculated using a critical value table or a calculator.

Rejection Criteria

(For every test, the null hypothesis is given by \(H_0: \mu = \mu_0\))

  • \(H_a: \mu \neq \mu_0\)

Reject \(H_0\) if \(z_0 < -z_{\alpha/2}\) or \(z_0 > z_{\alpha/2}\)

  • \(H_a: \mu > \mu_0\)

Reject \(H_0\) if \(z_0 > z_{\alpha}\)

  • \(H_a: \mu < \mu_0\)

Reject \(H_0\) if \(z_0 < -z_{\alpha}\)

Rejection Region for One-Sided Test (Upper)

The red dotted line represents \(z_{\alpha}\). If we calculate the test statistic, and find that it falls in the rejection region (i.e. \(z_0 > z_{\alpha}\)) then we have evidence that suggests we should reject the null hypothesis. Otherwise, we fail to reject the null hypothesis.

Rejection Region for One-Sided Test (Lower)

The red dotted line represents \(z_{\alpha}\). If we calculate the test statistic, and find that it falls in the rejection region (i.e. \(z_0 < z_{\alpha}\)) then we have evidence that suggests we should reject the null hypothesis. Otherwise, we fail to reject the null hypothesis.

Rejection Region for Two-Sided Test

The red dotted lines represent \(\pm z_{\alpha}\). If we calculate the test statistic, and find that it falls in one of the rejection regions (i.e. \(z_0 < -z_{\alpha}\) or \(z_0 > z_{\alpha}\)) then we have evidence that suggests we should reject the null hypothesis. Otherwise, we fail to reject the null hypothesis.

Example

Let’s consider the data set mtcars, which consists of data extracted from the 1974 Motor Trend US magazine, and focus on the data pertaining to miles per gallon (labeled in the data set as mpg). Suppose we know the standard deviation for mpg of our observations (given below), and suppose the population mean is believed to be 20.1 mpg.

sd(mtcars$mpg)
## [1] 6.026948

Now, suppose we took a survey of 100 random cars from the data set, and computed the sample mean as 21.84 mpg. Is there sufficient evidence to suggest that the mean mpg for the cars is not actually equal to 20.1? Use a significance value of 0.05.

Example (cont.)

Below is a histogram of the frequency for various ranges of miles per gallon in the data set. The red line shows the hypothesized mean, 20.1 mpg.

Solution

We calculate that \(z_0 = \dfrac{\bar{x}-\mu_0}{\sigma/\sqrt{n}} = \dfrac{21.84-20.1}{6.03/\sqrt{100}} \approx 2.89\).

Note that we are approximating \(\sigma\) to two places past the decimal.

We have that \(\pm z_{\alpha} = \pm z_{0.05} = \pm 1.64\).

Since \(z_0 > z_{\alpha}\), we reject the null hypothesis.

There is sufficient evidence to suggest that the mean miles per gallon of the population is not equal to 20.1 mpg.

Visualizing The Solution

This is how we would visually interpret the test statistic. The red lines are at values \(\pm z_{\alpha} \approx 1.64\) and the navy line is \(z_0 = 2.89\).

df <- data.frame(x = seq(-4, 4, by = 0.01))
ggplot(df, aes(x = x)) +
  stat_function(fun = dnorm, args = list(mean = 0, sd = 1), color = "grey", linewidth = 1.5) +
  geom_vline(xintercept = 1.64, linetype = "dashed", linewidth = 1.25, color = "red") +
  geom_vline(xintercept = -1.64, linetype = "dashed", linewidth = 1.25, color = "red") +
  geom_vline(xintercept = 2.8, linetype = "dotted", linewidth = 1.25, color = "navy") + 
  geom_ribbon(data = subset(df, x > 1.64), aes(ymin = 0, ymax = dnorm(x, mean = 0, sd = 1)), 
              fill = "blue", alpha = 0.5) +
    geom_ribbon(data = subset(df, x < -1.64), aes(ymin = 0, ymax = dnorm(x, mean = 0, sd = 1)), 
              fill = "blue", alpha = 0.5) +
  xlab(NULL) + ylab(NULL) + theme_minimal() + 
  theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) +
  theme(axis.text.y = element_blank(), axis.ticks.y = element_blank())