getwd() 
## [1] "/Users/jangsieun"
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Q1. 데이터 import한 후 head, str, summary 사용하여 데이터 살펴보기

dat <- ToothGrowth
head(dat)
##    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
str(dat)
## 'data.frame':    60 obs. of  3 variables:
##  $ len : num  4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
##  $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
##  $ dose: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
summary(dat)
##       len        supp         dose      
##  Min.   : 4.20   OJ:30   Min.   :0.500  
##  1st Qu.:13.07   VC:30   1st Qu.:0.500  
##  Median :19.25           Median :1.000  
##  Mean   :18.81           Mean   :1.167  
##  3rd Qu.:25.27           3rd Qu.:2.000  
##  Max.   :33.90           Max.   :2.000

Q2. len에 대한 box plot과 histogram 그려보기 (시각화)

dat %>%
  ggplot(aes( supp ,len)) + geom_boxplot()

dat %>%
  ggplot(aes( dose, len)) + geom_boxplot()
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?

boxplot(ToothGrowth$len)

hist(ToothGrowth$len)

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

Q4. 단측검정을 해야 하는가? 양측검정을 해야 하는가?

Q5. Z value를 구해야 하는가? t value를 구해야 하는가? (이유도 함께)

Q6. 이빨 길이의 표본 평균,표본 표준편차, 모집단 평균, 표본 크기를 각각 객체에 담으시오.

mean(ToothGrowth$len)
## [1] 18.81333
sd(ToothGrowth$len)
## [1] 7.649315
length(ToothGrowth$len)
## [1] 60
ToothGrowth.len.mean <- mean(ToothGrowth$len)
ToothGrowth.len.sd <- sd(ToothGrowth$len)
ToothGrowth.mean <- 17 
ToothGrowth.n <- 60 

Q7. pt 함수를 사용하여 p-value를 계산하시오.

t_value <- (ToothGrowth.len.mean - ToothGrowth.mean) / (ToothGrowth.len.sd / sqrt(ToothGrowth.n))
p_value <- 1 - pt(t_value, df=ToothGrowth.n - 1, lower.tail = FALSE)
p_value
## [1] 0.9643194

Q8.귀무가설을기각할수있는가?이빨길이에대해어떠한결론을내릴수있는가?

Q9~Q13: 기니피그의 이빨 길이가 18인지 아닌지 유의수준 0.05에서 검정하고자 한다. 아래 물음에 답하시오.

Q9. 귀무가설과 대립가설은 무엇인가?

  • H0: mu = 18
  • H1 : mu =! 18

Q10. 단측검정을 해야 하는가? 양측검정을 해야 하는가?

  • 양측 검정. 그 이유는 18인지 아닌지이기 때문에 28보다 작을 수도 있고 클 수도 있다. 단측검정으로는 한 측밖에 보이지 않기 때문에 양측검정으로 양끝을 봐야 한다.

Q11. Z value를 구해야 하는가? t value를 구해야 하는가? (이유도 함께)

  • t value. 그 이유는 60마리의모집단에서 실행한 거이기 때문

Q12. 이빨 길이의 표본 평균,표본 표준편차, 모집단 평균, 표본 크기를 각각 객체에 담으시오.

mean(ToothGrowth$len)
## [1] 18.81333
sd(ToothGrowth$len)
## [1] 7.649315
length(ToothGrowth$len)
## [1] 60

표본 평; 표본 표준편차; 모집단 평균( 가정된 값); 표본 크기

ToothGrowth.len.mean <- mean(ToothGrowth$len)
ToothGrowth.len.sd <- sd(ToothGrowth$len)
ToothGrowth.mean <- 18 
ToothGrowth.n <- 60 

Q13. pt 함수를 사용하여 p-value를 계산하시오.

t_value <- (ToothGrowth.len.mean - ToothGrowth.mean) / (ToothGrowth.len.sd / sqrt(ToothGrowth.n))
p_value <- 2 * pt(t_value, df=ToothGrowth.n - 1, lower.tail = FALSE)
p_value
## [1] 0.4134781

```

Q14.귀무가설을기각할수있는가?이빨길이에대해어떠한결론을내릴수있는가?

  • p_value는 0.4134781이 나왔다. 그러므로 귀무가설인 mu = 18를 기각할 수 없고 이빨의 길이가 18이라고 아니라고 판단 할 수 없다.