方法一
# 定义两组样本数据集
x <- c(48.5,47.2,55.5,24.8,47.4,36.9,27.8,13.5,71.6,44.1,65.1,53.2,36.1,33.1,54.1,58.8,40.2,56.4,52.8,40.9)
y <- c(9.3,10.9,9.7,14,8.5,12.7,9.8,10.1,8.2,11.2,8,12,7.9,7.6,11.3,12.3,8.4,7.1,10.9,9.4)
# 执行F检验判断方差是否相等
var.test(x, y)
# F test to compare two variances
#
# data: x and y
方法二
# 定义两组样本数据集
data <- data.frame(values=c(18, 19, 22, 25, 27, 28, 41, 45, 51, 55,
14, 15, 15, 17, 18, 22, 25, 25, 27, 34),
group=rep(c('A', 'B'), each=10))
# 执行F检验判断方差是否相等
var.test(values~group, data=data)
# F test to compare two variances
#
# data: values by group
# F = 4.3871, num df = 9, denom df = 9, p-value = 0.03825
# alternative hypothesis: true ratio of variances is not equal to 1
# 95 percent confidence interval:
# 1.089699 17.662528
# sample estimates:
# ratio of variances
# 4.387122