问题描述
我正在尝试对chisq和Fisher精确测试进行事后测试。我正在使用的数据帧是2x3。我运行了一个chisq检验,该检验产生了显着的p值,但是当我检查期望值时,该值小于5,因此我运行了Fisher精确检验,该检验也返回了小于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,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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)