为什么t.test返回R的最小p值2.2e – 16?

当我们在R中进行测试时,两组之间的差异非常大,则测试的p值将打印为2.2e – 16,这是假设检验程序R的打印行为。可以通过使用t检验函数作为t.test(“ Var1”,“ Var2”,var.equal = FALSE)$p.value来提取实际的p值。该p值不可能与2.2e – 16相同。

例1

> x1<-1:100
> y1<-100001:110000
> t.test(x1,y1,var.equal=FALSE)

输出结果

   Welch Two Sample t-test
data: x1 and y1
t = -3617.2, df = 10098, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-105006.9 -104893.1
sample estimates:
mean of x mean of y
   50.5 105000.5
> t.test(x1,y1,var.equal=FALSE)$p.value
[1] 0

例2

> x2<-sample(1:10,50,replace=TRUE)
> y2<-sample(500:510,replace=TRUE)
> t.test(x2,y2,var.equal=FALSE)

输出结果

   Welch Two Sample t-test
data: x2 and y2
t = -427.61, df = 12.789, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-500.4179 -495.3785
sample estimates:
mean of x mean of y
   5.9200 503.8182
> t.test(x2,y2,var.equal=FALSE)$p.value
[1] 5.881324e-28

范例3

> x3<-sample(101:110,50,replace=TRUE)
> y3<-sample(1001:1010,50,replace=TRUE)
> t.test(x3,y3,var.equal=FALSE)

输出结果

   Welch Two Sample t-test
data: x3 and y3
t = -1730.7, df = 97.907, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-901.4725 -899.4075
sample estimates:
mean of x mean of y
   105.38 1005.82
> t.test(x3,y3,var.equal=FALSE)$p.value
[1] 2.07048e-221

例子4

> x4<-sample(1001:1010,50,replace=TRUE)
> y4<-sample(100001:1000010,50)
> t.test(x4,y4,var.equal=FALSE)

输出结果

   Welch Two Sample t-test
data: x4 and y4
t = -14.798, df = 49, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-620129.5 -471835.6
sample estimates:
mean of x mean of y
   1005.6 546988.1
> t.test(x4,y4,var.equal=FALSE)$p.value
[1] 1.043251e-19