Introduction

Hypothesis testing is a fundamental method in inferential statistics used to evaluate assumptions about a population.

Terminology

  • Null Hypothesis (H₀): The default assumption (e.g., no effect or difference).
  • Alternative Hypothesis (H₁): The claim we test for.
  • p-value: The probability of observing data as extreme as ours, assuming H₀ is true.

Plotly Visualization

## Loading required package: ggplot2
## 
## 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

Plotly Visualization (BAR Chart)

ggplot2 Visualization 1

ggplot2 Visualization 2

Math Behind Hypothesis Testing

We use test statistics such as z or t values:

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

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

Significance and Errors

  • Type I Error: Rejecting H₀ when it’s true (α).
  • Type II Error: Not rejecting H₀ when H₁ is true (β).
  • Significance level (α): Common choices are 0.05 or 0.01.

Code for Simulation and Plot

set.seed(123)
group1 <- rnorm(30, mean = 5, sd = 1)
group2 <- rnorm(30, mean = 5.5, sd = 1)
t.test(group1, group2)
## 
##  Welch Two Sample t-test
## 
## data:  group1 and group2
## t = -3.0841, df = 56.559, p-value = 0.003156
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.1965426 -0.2543416
## sample estimates:
## mean of x mean of y 
##  4.952896  5.678338

Conclusion

Hypothesis testing provides a structured framework for making data-driven decisions under uncertainty. Always interpret results in the context of the study.