과제에 대한 간략한 설명

목표: 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

Q1: 데이터 불러오기

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

Q2: len 변수의 boxplot과 histogram

> Boxplot

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")

> Histogram

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")

Q3~Q8: 기니피그의 이빨 길이가 17 이상인지 유의수준 0.05에서 검정하고자 한다.

Q3: 귀무가설과 대립가설은 무엇인가?

  • 귀무가설 (H₀): μ = 17
  • 대립가설(H₁): μ > 17

Q4: 단측검정 혹은 양측검정?

단측검정을 수행해야 합니다. 연구 관심사가 기니피그의 이빨 길이가 17보다 큰지 여부에 초점이 맞춰져 있기 때문입니다.

Q5: Z-value or t-value?

We use the t-value here because the population standard deviation (σ) is unknown, so we estimate it using the sample standard deviation (s).

Q6: Setup Step for Hypothesis Testing

sample_mean <- mean(ToothGrowth$len)
sample_sd <- sd(ToothGrowth$len)
pop_mean <- 17
## 모집단 평균 (귀무가설에서 기준값)
sample_size <- length(ToothGrowth$len)

Q7: p-value

t_value
## [1] 1.836245
p_value
## [1] 0.0356806

Q8: Conclusion

if (p_value < 0.05) {
  cat("귀무가설을 기각합니다. 기니피그의 이빨 길이는 평균적으로 17보다 큽니다.\n")
} else {
  cat("귀무가설을 기각하지 못합니다. 기니피그의 이빨 길이는 평균적으로 17보다 크다고 할 수 없습니다.\n")
}
## 귀무가설을 기각합니다. 기니피그의 이빨 길이는 평균적으로 17보다 큽니다.