2024-06-10

What is Hypothesis Testing?

Hypothesis testing is a statistical method that helps determine the likelihood that a given hypothesis is true.

Null and Alternative Hypotheses

  • Null Hypothesis (H0): The default assumption that there is no effect or difference.
  • Alternative Hypothesis (H1): The assumption that there is an effect or difference.

Steps in Hypothesis Testing

  1. State the hypotheses.
  2. Choose the significance level.
  3. Calculate the test statistic.
  4. Determine the p-value.
  5. Make a decision.

Example: One-Sample t-Test

Let’s say we want to test if the average height of students is 170 cm.

Visualizing Data

library(plotly)
data <- data.frame(height = rnorm(100, mean = 170, sd = 10))
plot_ly(data, x = ~height, type = 'histogram')

ggplot2 Plot: Density

library(ggplot2)
ggplot(data, aes(x = height)) + geom_density(fill = "blue", alpha = 0.5)

ggplot2 Plot: Boxplot

ggplot(data, aes(y = height)) + geom_boxplot(fill = "orange", color = "blue")

Hypothesis Testing Formula

The test statistic for a one-sample t-test is given by: \[ t = \frac{\bar{x} - \mu}{s / \sqrt{n}} \]

R Code for t-Test

t_test_result <- t.test(data$height, mu = 170)
t_test_result
## 
##  One Sample t-test
## 
## data:  data$height
## t = 1.7931, df = 99, p-value = 0.07601
## alternative hypothesis: true mean is not equal to 170
## 95 percent confidence interval:
##  169.8169 173.6192
## sample estimates:
## mean of x 
##   171.718

```