2025-02-07

Introduction

Hypothesis Testing is a statistical method to decide whether the data sufficiently supports a particular hypothesis.

\[ H_0: \text{Null Hypothesis} \] \[ H_A: \text{Alternative Hypothesis} \]

Key Components of a Hypothesis Test

  • Null Hypothesis (H₀): The assumption that there is no difference between groups or variables being studied.
  • Alternative Hypothesis (H₁): The statement that researchers are trying to prove (often the same as the research hypothesis).
  • Significance Level (α): The probability that the event could have occured by chance (commonly 0.05).
  • p-value: The number describing the likelihood of obtaining the observed data under the hull hypothesis.

Example: Testing Mean MPG

We use the mtcars dataset to test if the mean miles per gallon (MPG) is significantly different from 20.

## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Visualizing Data

T-Test

Performing a one-sample t-test:

## 
##  One Sample t-test
## 
## data:  mtcars$mpg
## t = 0.08506, df = 31, p-value = 0.9328
## alternative hypothesis: true mean is not equal to 20
## 95 percent confidence interval:
##  17.91768 22.26357
## sample estimates:
## mean of x 
##  20.09062

Test Statistic

The test statistic follows:

\[ t = \frac{\bar{x} - \mu}{s/\sqrt{n}} \]

where: - \(\bar{x}\) is the sample mean - \(\mu\) is the hypothesized mean - \(s\) is the sample standard deviation - \(n\) is the sample size

Boxplot

3D Visualization

Conclusion

Hypothesis testing is a useful tool that aids our decision-making. Making a data-informed decision is the best choice.