R语言的t检验(双边)

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
  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值