我将不胜感激帮助解决以下问题。我正在使用组内 (4) 数据进行 Kruskal-Wallis 测试,并按照此处的说明进行操作:http ://rcompanion.org/handbook/F_08.html 。第一步是按中位数对组进行排序:
$senseofpresence$Condition = factor(senseofpresence$condition, levels=c("A", "B", $"C", "D", "E"))
但是,当按中位数对组进行排序时,我收到以下错误:
$<-.data.frame
(*tmp*
, "Condition", value = integer(0))中的错误:替换有 0 行,数据有 128
我不确定导致错误的原因以及 KW 测试和 Dunn 事后测试是否有效,无论错误消息如何。代码和结果如下。感谢您帮助解决问题。这是我在 StackOverflow 上的第一篇文章,我对 R 也很陌生。
> senseofpresence$Condition = factor(senseofpresence$Condition,
>+ levels=unique(senseofpresence$Condition))
> senseofpresence$PresentPlace1.f = factor(senseofpresence$PresentPlace1,
>+ ordered = TRUE)
> xtabs( ~ Condition + PresentPlace1.f,
>+ data = senseofpresence)
PresentPlace1.f
>Condition 1 2 3 4 5 6 7
A 0 0 0 2 5 11 10
B 1 1 1 1 11 9 1
C 2 3 5 3 5 8 1
D 0 2 0 1 10 7 6
E 1 4 1 1 7 4 4
>
> XT = xtabs( ~ Condition + PresentPlace1.f,
>+ data = senseofpresence)
>
> prop.table(XT,
>+ margin = 1)
PresentPlace1.f
>Condition 1 2 3 4 5 6 >7
> A 0.00000000 0.00000000 0.00000000 0.07142857 0.17857143 0.39285714 >0.35714286
> B 0.04000000 0.04000000 0.04000000 0.04000000 0.44000000 0.36000000 >0.04000000
C 0.07407407 0.11111111 0.18518519 0.11111111 0.18518519 0.29629630 >0.03703704
> D 0.00000000 0.07692308 0.00000000 0.03846154 0.38461538 0.26923077 >0.23076923
E 0.04545455 0.18181818 0.04545455 0.04545455 0.31818182 0.18181818 >0.18181818
> library (lattice)
>
> histogram( ~ PresentPlace1.f | Condition,
>+ data=senseofpresence,
>+ layout=c(1,3)
>+ )
>
> library(FSA)
> Summarize(PresentPlace1 ~ Condition,
>+ data=senseofpresence,
>+ digits=3)
> Condition n mean sd min Q1 median Q3 max
1 A 28 6.036 0.922 4 5.75 6.0 7 7
2 B 25 5.040 1.338 1 5.00 5.0 6 7
3 C 27 4.259 1.745 1 3.00 5.0 6 7
4 D 26 5.462 1.334 2 5.00 5.5 6 7
5 E 22 4.682 1.887 1 3.25 5.0 6 7
> kruskal.test(PresentPlace1 ~ Condition,
>+ data = senseofpresence)
> Kruskal-Wallis rank sum test
>data: PresentPlace1 by Condition
>Kruskal-Wallis chi-squared = 19.754, df = 4, p-value = 0.0005585
>
> senseofpresence$Condition = factor(senseofpresence$condition,
>+ levels=c("A", "B", "C", "D", "E"))
>Error in `$<-.data.frame`(`*tmp*`, "Condition", value = integer(0)) :
> replacement has 0 rows, data has 128
>
> levels(senseofpresence$Condition)
>[1] "A" "B" "C" "D" "E"
>
> library(FSA)
>
> DT = dunnTest(PresentPlace1 ~ Condition,
>+ data=senseofpresence,
>+ method="bh") # Adjusts p-values for multiple comparisons;
> DT
>Dunn (1964) Kruskal-Wallis multiple comparison
> p-values adjusted with the Benjamini-Hochberg method.
> Comparison Z P.unadj P.adj
>1 A - B 2.7334681 6.267119e-03 0.0208903954
>2 A - C 4.1353289 3.544465e-05 0.0003544465
>3 B - C 1.3087557 1.906171e-01 0.2723101491
>4 A - D 1.6053479 1.084173e-01 0.2168345127
>5 B - D -1.1242981 2.608866e-01 0.3261082038
>6 C - D -2.4681705 1.358056e-02 0.0339514018
>7 A - E 2.9473396 3.205210e-03 0.0160260486
>8 B - E 0.2995078 7.645526e-01 0.7645526055
>9 C - E -0.9599074 3.371018e-01 0.3745575517
>10 D - E 1.3893854 1.647156e-01 0.2745259737