##先檢視資料
structure(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
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
densityplot( ~ extra, groups = group, data = sleep,auto.key = TRUE,lty = c(1, 2), plot.points = T, type = "g", xlab = "numeric increase in hours of sleep", main = "numeric increase in hours of sleep for 2 type of drugs ")
##由上圖可以看出,就整體分布而言,在”numeric increase in hours of sleep”的結果中,增長0以上的部分GROUP2大於GROUP1,所以GROUP2的效果maybe較好
qq(group ~ extra, data = sleep,type = c("p", "g"),pch = ".",cex = 5 ,aspect = 1)
##從上圖可以看出,GROUP2在”numeric increase in hours of sleep”的結果高於GROUP1
##接著做t-Test
t.test(extra ~ group, data = sleep)
##
## Welch Two Sample t-test
##
## data: extra by group
## t = -1.8608, df = 17.776, p-value = 0.07939
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
## -3.3654832 0.2054832
## sample estimates:
## mean in group 1 mean in group 2
## 0.75 2.33
##從t-Test的結果看到
##在虛無假設為兩組沒有差異之下,P值>0.05,故無法拒絕虛無假設,因此兩組沒有顯著差異
##95 percent confidence interval包含0,表示兩組的差異未達顯著水準
##t = -1.8608 的絕對值<2,表示兩組的差異未達顯著水準