1

我正在尝试对以下数据集进行 kruskal wallis 测试:

e<-c(0.0018, 0.0021, 0.0028, 0.0029, 0.0044, 0.0045, 0.0074, 0.00325140981291511,0.00325140981291511, 0.00325140981291511, 0.0079, 0.001978252063446,0.00684016798870973, 0.00384959728634123, 0.0093, 0.011, 0.014, 0.022, 0.083, 0.48, 0.49, 1.2)

f<-c(0.0145458371613749, 0.0355067948032862, 0.0654819408270916, 0.107370481645772, 0.165362828209794, 0.0654819408270916, 0.253, 0.344, 0.42, 1.3, 2.7, 3.14, 3.93, 4.48, 5.48, 17)

当我使用此代码运行 kruskal 测试时kruskal.test(e,f),我收到此错误:

Error in kruskal.test.default(e, f) : 
  'x' and 'g' must have the same length
4

1 回答 1

1

如 中所述?kruskal.test,您的第二个参数必须是指示组的因素。所以:

# Combine the data in a single vector
x <- c(e,f)
# create a group indicator
groups <- rep(c(1,2), 
              times = c(length(e), length(f))
              )
# profit
kruskal.test(x, groups)

#   Kruskal-Wallis rank sum test
# 
# data:  x and groups
# Kruskal-Wallis chi-squared = 18.136, df = 1, p-value = 2.057e-05
于 2017-06-13T14:55:03.763 回答