r - Chisq 和 Fishers 事后检验
问题描述
我正在尝试对 chisq 和 Fisher 精确检验进行事后检验。我使用的数据框是 2x3。我运行了一个 chisq 检验,它产生了一个显着的 p 值,但是当我检查预期值时,有一些小于 5,所以我运行了 Fishers 精确检验,它也返回了一个小于 0.05 的 p 值。我现在正在尝试测试以查看哪些交互很重要,因此我尝试运行 chisq.posthoc.test、pairwise.fisher 和 fisher.multcomp 测试,但返回的值很奇怪,我不确定如果我正在运行的代码是错误的,或者下一步该怎么做。我对 R 还是比较陌生,所以我有点卡住了。
如果有人可以帮助我了解正在发生的事情以及我接下来应该做什么,我将不胜感激。
tally_spawnsl<-
data%>%
group_by(Spawn_Type, spawn_false,Lunar_Phase_Boxed) %>%
filter(spawn_false=="TRUE")%>%
tally()
print.data.frame(tally_spawnsl)
Spawn_Type spawn_false Lunar_Phase_Boxed n
1 Group TRUE Full 372
2 Group TRUE Half 134
3 Group TRUE New 348
4 Pair TRUE Full 20
5 Pair TRUE Half 3
6 Pair TRUE New 4
spawntypesl<- data.frame(
expand.grid(lunarphase=c("Full","Half","New"),
type=c("Group","Pair")),
count=c(372,134,348,20,3,4))
spawntypesl
lunarphase type count
1 Full Group 372
2 Half Group 134
3 New Group 348
4 Full Pair 20
5 Half Pair 3
6 New Pair 4
tablel<-xtabs(count~lunarphase+type, data=spawntypesl)
tablel
type
lunarphase Group Pair
Full 372 20
Half 134 3
New 348 4
summary(tablel)
Call: xtabs(formula = count ~ lunarphase + type, data = spawntypesl)
Number of cases in table: 881
Number of factors: 2
Test for independence of all factors:
Chisq = 10.236, df = 2, p-value = 0.005988
Chi-squared approximation may be incorrect
chisq.test(tablel,simulate.p.value=TRUE)
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: tablel
X-squared = 10.236, df = NA, p-value = 0.002999
chisq.test(tablel)$expected
type
lunarphase Group Pair
Full 379.9864 12.013621
Half 132.8014 4.198638
New 341.2123 10.787741
library(devtools)
devtools::install_github("ebbertd/chisq.posthoc.test")
chisq.posthoc.test::chisq.posthoc.test(tablel, method = "bonferroni")```
Dimension Value Group Pair
1 Full Residuals -3.14127171999929 3.14127171999929
2 Full p values 0.0101* 0.0101*
3 Half Residuals 0.646538369476683 -0.646538369476691
4 Half p values 1 1
5 New Residuals 2.70881379836813 -2.70881379836813
6 New p values 0.0405* 0.0405*
####Fisher Test for lunar phase and spawn type####
fishertestl<-fisher.test(tablel)
fishertestl
Fisher's Exact Test for Count Data
data: tablel
p-value = 0.005426
alternative hypothesis: two.sided
fishertestl$p.value
[1] 0.005426258
fisher.multcomp(tablel, p.method = "none")
Pairwise comparisons using Fisher's exact test for count data
data: tablel
Full Half
Half 0.222207 -
New 0.002811 0.4062
P value adjustment method: none
> chisq.posthoc.test::chisq.posthoc.test(tablel, method = "bonferroni")
Dimension Value Group Pair
1 Full Residuals -3.14127171999929 3.14127171999929
2 Full p values 0.0101* 0.0101*
3 Half Residuals 0.646538369476683 -0.646538369476691
4 Half p values 1 1
5 New Residuals 2.70881379836813 -2.70881379836813
6 New p values 0.0405* 0.0405*
Warning message:
In chisq.test(x, ...) : Chi-squared approximation may be incorrect
> fisher.multcomp(tablel, p.method = "bonferroni")
Pairwise comparisons using Fisher's exact test for count data
data: tablel
Full Half
Half 0.666620 -
New 0.008432 1
P value adjustment method: bonferroni
> chisq.posthoc.test::chisq.posthoc.test(tablel, method = "none")
Dimension Value Group Pair
1 Full Residuals -3.14127171999929 3.14127171999929
2 Full p values 0.0017* 0.0017*
3 Half Residuals 0.646538369476683 -0.646538369476691
4 Half p values 0.5179 0.5179
5 New Residuals 2.70881379836813 -2.70881379836813
6 New p values 0.0068* 0.0068*
Warning message:
In chisq.test(x, ...) : Chi-squared approximation may be incorrect
> fisher.multcomp(tablel, p.method = "none")
Pairwise comparisons using Fisher's exact test for count data
data: tablel
Full Half
Half 0.222207 -
New 0.002811 0.4062
P value adjustment method: none