T检验是小样本均值比较的正选手段。根据抽样数据的性质不同,T检验又分为单样本T检验、配对T检验和独立样本T检验,并有一些诸如总体正态分布————、方差齐性等前置要求。这里我们只简单讲一下配对T检验的实现过程。
首先我们生成一组事前和事后的绩效样本:
>pretest<-c(85,78,82,79,73,68)
>aftertest<-c(86,78,80,82,75,70)
然后用T.TEST命令执行T检验并查看结果:
>t.test(pretest,aftertest,paired=T)
Pairedt-test
data:pretest and aftertest
t = -1.3693, df = 5, p-value =0.2292
alternative hypothesis: truedifference in means is not equal to 0
95 percent confidenceinterval:
-2.87728750.8772875
sample estimates:
mean of thedifferences
-1
由于默认是双尾检验,P值应该小于0.025才会推翻原假设,而检验P值结果为0.2292,故不能推翻原假设,即事前跟事后没有明显差异。
上面默认是双尾检验,下面看一下单尾(大于)检验:
>t.test(pretest,aftertest,paired=T,alternative="greater")
Pairedt-test
data:pretest and aftertest
t = -1.3693, df = 5, p-value =0.8854
alternative hypothesis: truedifference in means is greater than 0
95 percent confidenceinterval:
-2.471583Inf
sample estimates:
mean of thedifferences
-1
毫无意外,检验不通过,无明显差异。
T.TEST的默认置信度为0.95,如果调整置信度的话,只需加入conf.level参数:
>t.test(pretest,aftertest,paired=T,alternative="greater",conf.level=.99)
Pairedt-test
data:pretest and aftertest
t = -1.3693, df = 5, p-value =0.8854
alternative hypothesis: truedifference in means is greater than 0
99 percent confidenceinterval:
-3.457397Inf
sample estimates:
mean of thedifferences
-1