R中chi-sq的事后检验 [英] Post-Hoc tests for chi-sq in R
问题描述
我有一张看起来像这样的桌子.
I have a table that looks like this.
> dput(theft_loc)
structure(c(13704L, 14059L, 14263L, 14450L, 14057L, 15503L, 14230L,
16758L, 15289L, 15499L, 16066L, 15905L, 18531L, 19217L, 12410L,
13398L, 13308L, 13455L, 13083L, 14111L, 13068L, 19569L, 18771L,
19626L, 20290L, 19816L, 20923L, 20466L, 20517L, 19377L, 20035L,
20504L, 20393L, 22409L, 22289L, 7997L, 8106L, 7971L, 8437L, 8246L,
9090L, 8363L, 7934L, 7874L, 7909L, 8150L, 8191L, 8746L, 8277L,
27194L, 25220L, 26034L, 27080L, 27334L, 30819L, 30633L, 10452L,
10848L, 11301L, 11494L, 11265L, 11985L, 11038L, 12104L, 13368L,
14594L, 14702L, 13891L, 12891L, 12939L), .Dim = c(7L, 10L), .Dimnames = structure(list(
c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"), c("BAYVIEW", "CENTRAL", "INGLESIDE",
"MISSION", "NORTHERN", "PARK", "RICHMOND", "SOUTHERN", "TARAVAL",
"TENDERLOIN")), .Names = c("", "")), class = "table")
我运行了 chisq.test
并且结果显着.我现在想运行一些成对测试,看看重要性在哪里.我尝试使用 fifer
包和 chisq.post.test
函数,但我收到一个错误,提示 out of workspace
.
I ran a chisq.test
and the results came back significant. I now want to run some pairwise tests to see where the significance lies. I tried to use the fifer
package and the chisq.post.test
function but i get an error that says out of workspace
.
还有哪些其他方法可以运行多重比较测试?
What other ways can I run the multiple comparisons test?
推荐答案
This will work (try chisq.test
而不是默认的 fisher.test
(exact) in事后测试):
This will work (try chisq.test
instead of the default fisher.test
(exact) in post hoc test):
(Xsq <- chisq.test(theft_loc)) # Prints test summary, p-value very small,
# Pearson's Chi-squared test
# data: theft_loc
# X-squared = 1580.1, df = 54, p-value < 2.2e-16 # reject null hypothesis for independence
library(fifer)
chisq.post.hoc(theft_loc, test='chisq.test')
带输出
Adjusted p-values used the fdr method.
comparison raw.p adj.p
1 Sunday vs. Monday 0.0000 0.0000
2 Sunday vs. Tuesday 0.0000 0.0000
3 Sunday vs. Wednesday 0.0000 0.0000
4 Sunday vs. Thursday 0.0000 0.0000
5 Sunday vs. Friday 0.0000 0.0000
6 Sunday vs. Saturday 0.0000 0.0000
7 Monday vs. Tuesday 0.0000 0.0000
8 Monday vs. Wednesday 0.0000 0.0000
9 Monday vs. Thursday 0.0000 0.0000
10 Monday vs. Friday 0.0000 0.0000
11 Monday vs. Saturday 0.0000 0.0000
12 Tuesday vs. Wednesday 0.1451 0.1451
13 Tuesday vs. Thursday 0.0000 0.0000
14 Tuesday vs. Friday 0.0000 0.0000
15 Tuesday vs. Saturday 0.0000 0.0000
16 Wednesday vs. Thursday 0.0016 0.0017
17 Wednesday vs. Friday 0.0000 0.0000
18 Wednesday vs. Saturday 0.0000 0.0000
19 Thursday vs. Friday 0.0000 0.0000
20 Thursday vs. Saturday 0.0000 0.0000
21 Friday vs. Saturday 0.0000 0.0000
正如我们所看到的,除了一对之外,所有的成对测试都很重要,我们也可以使用不同的p-value-correction
(通过改变默认的control
code>fdr 到 bonferroni
).
As we can see, all the pairwise tests except a couple are significant, we can use different p-value-correction
too (by changing the control
from default fdr
to bonferroni
).
这篇关于R中chi-sq的事后检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!