R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Q1. 데이터를 불러온 뒤 데이터 살펴보기
data(ToothGrowth)
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에 대한 boxplot과 histogram 그려서 눈으로 확인하기기
boxplot(dat$len)

hist(dat$len)

# Q3~Q8: 기니피그의 이빨 길이가 17 이상인지 유의수준 0.05에서 검정하고자 한다. 아래 물음에 답하시오
# Q3. 귀무가설과 대립가설은 무엇인가?
# H0 : The average length of guinea pig's teeth is less than 17
# H1 : The average length of guinea pig's teeth is equal to or more than 17

# Q4. 단측검정을 해야 하는가? 양측검정을 해야 하는가?
# We need to use one-tailed test, because the alternative hypothesis assumes that the average value can differ in only one direction.

# Q5. Z-value를 구해야 하는가? 아니면 t-value를 구해야 하는가?
# t-value, because sample size is small and we don't know its standard deviation

# Q6. 이빨 길이의 표본평균, 표본 표준편차, 모집단 평균, 표본 크기를 각각 sample_mean, sample_sd, pop_mean, sample_size이라는 객체에 담으시오. 
sample_mean <- mean(dat$len)
sample_sd <- sd(dat$len)
pop_mean <- 17
sample_size <- length(dat$len)

# Q7. pt() 함수를 사용하여 p-value를 구하시오.
t_value <- (sample_mean - pop_mean)/(sample_sd / sqrt(sample_size))
p_value <- 1-pt(t_value, df = sample_size-1)
p_value
## [1] 0.0356806
# Q8.귀무가설을 기각할 수 있는가? 이빨 길이에 대해 어떠한 결론을 내릴 수 있는가?
# Since p_value is less than 0.05, the null hypothesis can be rejected. This shows that the average tooth length of guinea pigs is significantly equal to or more than 17.

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.