よく使われる2つの平均値の差の検定と、差の95%の信頼区間をもとめる例。
> x1<-c(3,4,5,6,7)
> x2<-c(0,1,2,3,4)
> t.test(x1,x2)
Welch Two Sample t-test
data: x1 and x2
t = 3, df = 8, p-value = 0.01707
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.6939959 5.3060041
sample estimates:
mean of x mean of y
5 2
同様にデータに対応がある場合:
> x2<-c(1,1,2,3,4)
> x1<-c(3,4,5,6,6)
> t.test(x1,x2,paired=TRUE)
Paired t-test
data: x1 and x2
t = 10.6145, df = 4, p-value = 0.0004460
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.919913 3.280087
sample estimates:
mean of the differences
2.6
> x1<-c(3,4,5,6,7)
> x2<-c(0,1,2,3,4)
> t.test(x1,x2)
Welch Two Sample t-test
data: x1 and x2
t = 3, df = 8, p-value = 0.01707
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.6939959 5.3060041
sample estimates:
mean of x mean of y
5 2
同様にデータに対応がある場合:
> x2<-c(1,1,2,3,4)
> x1<-c(3,4,5,6,6)
> t.test(x1,x2,paired=TRUE)
Paired t-test
data: x1 and x2
t = 10.6145, df = 4, p-value = 0.0004460
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.919913 3.280087
sample estimates:
mean of the differences
2.6