使用R完成均值查验
使用R完成均值检验
[1] -2.947929 3.250022
结果说明在置信度为95%的情况下总体的均值区间为[-2.947929 3.250022]
One Sample t-test
data: x
t = -0.1736, df = 19, p-value = 0.864
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-2.886276 2.444247
sample estimates:
mean of x
-0.2210147
------------------------------------------------------------------------------------
双样本均值检验
对t.test函数,R的帮助文档有很好的例子:
t检验和Z检验都可用于均值检验。
单样本均值检验
当样本容量小于30时使用t检验,当样本容量大于30时使用Z检验
Z检验使用例子:
单样本均值检验
当样本容量小于30时使用t检验,当样本容量大于30时使用Z检验
Z检验使用例子:
library(UsingR) x<-rnorm(50,0,5) simple.z.test(x,5)运行结果:
[1] -2.947929 3.250022
结果说明在置信度为95%的情况下总体的均值区间为[-2.947929 3.250022]
t检验使用例子:
x<-rnorm(20,0,5) t.test(x)运行结果:
One Sample t-test
data: x
t = -0.1736, df = 19, p-value = 0.864
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-2.886276 2.444247
sample estimates:
mean of x
-0.2210147
------------------------------------------------------------------------------------
双样本均值检验
对t.test函数,R的帮助文档有很好的例子:
require(graphics) t.test(1:10, y = c(7:20)) # P = .00001855 t.test(1:10, y = c(7:20, 200)) # P = .1245 -- NOT significant anymore ## Classical example: Student's sleep data plot(extra ~ group, data = sleep) ## Traditional interface with(sleep, t.test(extra[group == 1], extra[group == 2])) ## Formula interface t.test(extra ~ group, data = sleep)此外《统计建模与R语言》从P206页开始有讨论正太总体均值的建设检验,书中作者编写了自己的均值检验函数mean.test1(针对单个总体)和mean.test2(针对两个总体),也有相对应的使用t.test函数进行检验的例子,具体应用时可以参考。