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:
data(sleep)
?sleep
## httpd 도움말 서버를 시작합니다 ... 완료
sleep
## extra group ID
## 1 0.7 1 1
## 2 -1.6 1 2
## 3 -0.2 1 3
## 4 -1.2 1 4
## 5 -0.1 1 5
## 6 3.4 1 6
## 7 3.7 1 7
## 8 0.8 1 8
## 9 0.0 1 9
## 10 2.0 1 10
## 11 1.9 2 1
## 12 0.8 2 2
## 13 1.1 2 3
## 14 0.1 2 4
## 15 -0.1 2 5
## 16 4.4 2 6
## 17 5.5 2 7
## 18 1.6 2 8
## 19 4.6 2 9
## 20 3.4 2 10
str(sleep)
## 'data.frame': 20 obs. of 3 variables:
## $ extra: num 0.7 -1.6 -0.2 -1.2 -0.1 3.4 3.7 0.8 0 2 ...
## $ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
## $ ID : Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
summary(sleep)
## extra group ID
## Min. :-1.600 1:10 1 :2
## 1st Qu.:-0.025 2:10 2 :2
## Median : 0.950 3 :2
## Mean : 1.540 4 :2
## 3rd Qu.: 3.400 5 :2
## Max. : 5.500 6 :2
## (Other):8
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
sleep_group_1 <- sleep$extra[sleep$group == 1]
sleep_group_2 <- sleep$extra[sleep$group == 2]
sleep_group_1
## [1] 0.7 -1.6 -0.2 -1.2 -0.1 3.4 3.7 0.8 0.0 2.0
sleep_group_2
## [1] 1.9 0.8 1.1 0.1 -0.1 4.4 5.5 1.6 4.6 3.4
shapiro_group_1 <- shapiro.test(sleep_group_1)
shapiro_group_2 <- shapiro.test(sleep_group_2)
shapiro_group_1
##
## Shapiro-Wilk normality test
##
## data: sleep_group_1
## W = 0.92581, p-value = 0.4079
shapiro_group_2
##
## Shapiro-Wilk normality test
##
## data: sleep_group_2
## W = 0.9193, p-value = 0.3511
# paired t-test
t_test_group1 <- t.test(sleep_group_1, paired=FALSE)
t_test_group1
##
## One Sample t-test
##
## data: sleep_group_1
## t = 1.3257, df = 9, p-value = 0.2176
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -0.5297804 2.0297804
## sample estimates:
## mean of x
## 0.75
# Since the p value is greater than 0.05, the null hypothesis cannot be rejected, so there is no difference in the average before and after the sleeping pill used in group 1 was administered. Therefore, the sleeping pills used in group 1 are not effective.
# paired t_test
t_test_group2 <- t.test(sleep_group_2, paired=FALSE)
t_test_group2
##
## One Sample t-test
##
## data: sleep_group_2
## t = 3.6799, df = 9, p-value = 0.005076
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## 0.8976775 3.7623225
## sample estimates:
## mean of x
## 2.33
# Since the p value is less than 0.05, the null hypothesis cannot be rejected, so there is a difference in the average before and after the sleeping pill used in group 2 was administered. Therefore, the sleeping pills used in group 2 are effective.
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.