xa <- c(134, 146, 104, 119, 124, 161, 107, 83, 113, 129, 97, 123)
xb <- c(70, 118, 101, 85, 107, 132, 94)
#方法1 先判断方差的齐次性
var.test(xa,xb,alternative = "two.sided")
F test to compare two variances
data: xa and xb
F = 1.0755, num df = 11, denom df = 6, p-value = 0.9788
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.198811 4.173718
sample estimates:
ratio of variances
1.07552
#t的双边检验
t.test(xa,xb,alternative="two.sided",paired=F,var.equal=F,conf.level=0.95)
Welch Two Sample t-test
data: xa and xb
t = 1.9107, df = 13.082, p-value = 0.07821
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.469073 40.469073
sample estimates:
mean of x mean of y
120 101
#方法2
x <- c(134, 146, 104, 119, 124, 161, 107, 83, 113, 129, 97, 123,70, 118, 101, 85, 107, 132, 94)
a <- factor(c(rep(1,12),rep(2,7)))
bartlett.test(x~a) # bartlett.test方差齐性检验
var.test(x~a) #var.test方差齐性检验
t.test(high,low,paired = FALSE)
Welch Two Sample t-test
data: xa and xb
t = 1.9107, df = 13.082, p-value = 0.07821
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.469073 40.469073
sample estimates:
mean of x mean of y
120 101
#方法3
vdf1<-s1**2/n1; vdf2<-s2**2/n2
vdf<-(vdf1+vdf2)**2
vdf<- vdf/(vdf1**2/(n1-1)+vdf2**2/(n2-1))
t <- abs(x1-x2)/sqrt(vdf1+vdf2)
p<- 2*pt(t,vdf,lower.tail=FALSE)
t;p
[1] 1.9107
[1] 0.07820704