访问量: 9 次浏览
费雪的 F 检验计算出较大方差和较小方差之间的比率。当我们想检查三个或更多组的平均值是否不同时,我们就会使用 F 检验。F 检验是用来评估两个种群(A 和 B)的方差是否相等。方法很简单,就是取大方差和小方差之间的比值。R 编程中的 var.test() 函数在 2 个正常种群之间进行 F 检验,假设 2 个种群的方差相等。
F = 较大样本方差 / 较小样本方差
var.test(x, y) 测试两个样本之间的方差是否相等。var.test(x, y, alternative = "two.sided")。语法:
var.test(x, y, alternative = "two.sided")
参数:
x, y:数字向量。alternative:指定替代假设的字符串。让我们有两个样本 x,y。R 函数 var.test() 可以用来比较两个方差,如下:
# Taking two samples
x <- rnorm(249, mean = 20)
y <- rnorm(79, mean = 30)
# var test in R
var.test(x, y, alternative = "two.sided")
输出:
F test to compare two variances
data: x and y
F = 0.88707, num df = 248, denom df = 78, p-value = 0.4901
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.6071405 1.2521004
sample estimates:
ratio of variances
0.8870677
它返回以下内容:
F 检验的 p 值为 p = 0.4901,大于 α 水平 0.05。综上所述,这两个样本之间没有差异。
让我们有两个随机人口的两个随机样本。测试两个人口是否有相同的方差:
# Taking two random samples
A = c(16, 17, 25, 26, 32,
34, 38, 40, 42)
B = c(600, 590, 590, 630, 610, 630)
# var test in R
var.test(A, B, alternative = "two.sided")
输出:
F test to compare two variances
data: A and B
F = 0.27252, num df = 8, denom df = 5, p-value = 0.1012
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.04033118 1.31282683
sample estimates:
ratio of variances
0.2725248
它返回以下内容:
F 检验的 p 值为 p = 0.1012,大于 α 水平 0.05。综上所述,这两个样本之间没有差异。
让我们有两个随机样本:
# Taking two random samples
x = c(25, 29, 35, 46, 58, 66, 68)
y = c(14, 16, 24, 28, 32, 35,
37, 42, 43, 45, 47)
# var test in R
var.test(x, y)
输出:
F test to compare two variances
data: x and y
F = 2.4081, num df = 6, denom df = 10, p-value = 0.2105
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.5913612 13.1514157
sample estimates:
ratio of variances
2.4081
它返回以下内容:
F 检验的 p 值为 p = 0.2105,大于 α 水平 0.05。综上所述,两个样本之间没有差异。