Hypothesis testing is a statistical method that helps determine the likelihood that a given hypothesis is true.
2024-06-10
Hypothesis testing is a statistical method that helps determine the likelihood that a given hypothesis is true.
Let’s say we want to test if the average height of students is 170 cm.
library(plotly) data <- data.frame(height = rnorm(100, mean = 170, sd = 10)) plot_ly(data, x = ~height, type = 'histogram')
library(ggplot2) ggplot(data, aes(x = height)) + geom_density(fill = "blue", alpha = 0.5)
ggplot(data, aes(y = height)) + geom_boxplot(fill = "orange", color = "blue")
The test statistic for a one-sample t-test is given by: \[ t = \frac{\bar{x} - \mu}{s / \sqrt{n}} \]
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
```