목표: R의 내장 데이터인 ToothGrowth에서 ’len’이라는 변수의
표본평균에 대한 가설검정 수행하기.
| Column Name | Description |
|---|---|
| len | Length of teeth measured in 60 guinea pigs |
| supp | Type of supplement given: Orange Juice (OJ) or Vitamin C (VC) |
| dose | Dosage level provided: 0.5, 1.0, or 2.0 mg/day |
head(data)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
library(ggplot2)
ggplot(ToothGrowth, aes(x = supp, y = len)) +
geom_boxplot(fill = "lightblue") +
labs(title = "Box Plot of Tooth Length by Supplement Type",
x = "Supplement Type", y = "Tooth Length")
library(ggplot2)
ggplot(ToothGrowth, aes(x = len)) +
geom_histogram(binwidth = 2, fill = "skyblue", color = "black") +
labs(title = "Histogram of Tooth Length",
x = "Tooth Length", y = "Frequency")
단측검정을 수행해야 합니다. 연구 관심사가 기니피그의 이빨 길이가 17보다 큰지 여부에 초점이 맞춰져 있기 때문입니다.
We use the t-value here because the population standard deviation (σ) is unknown, so we estimate it using the sample standard deviation (s).
sample_mean <- mean(ToothGrowth$len)
sample_sd <- sd(ToothGrowth$len)
pop_mean <- 17
## 모집단 평균 (귀무가설에서 기준값)
sample_size <- length(ToothGrowth$len)
t_value
## [1] 1.836245
p_value
## [1] 0.0356806
if (p_value < 0.05) {
cat("귀무가설을 기각합니다. 기니피그의 이빨 길이는 평균적으로 17보다 큽니다.\n")
} else {
cat("귀무가설을 기각하지 못합니다. 기니피그의 이빨 길이는 평균적으로 17보다 크다고 할 수 없습니다.\n")
}
## 귀무가설을 기각합니다. 기니피그의 이빨 길이는 평균적으로 17보다 큽니다.