Chisq and Fishers post hoc tests

2k views Asked by At

I am trying to do post hoc tests on both a chisq and a Fisher exact test. The dataframe I am using is a 2x3. I ran a chisq test which produced a significant p-value, but when I checked the expected values there were some less than 5, so I ran a Fishers exact test, which also returned a p-value less than 0.05. I am trying to now test to see which interactions are significant so I tried to run a chisq.posthoc.test, a pairwise.fisher, and a fisher.multcomp test, but the returned values came back strange, and I'm not sure if the code I am running is wrong, or what to do next. I'm still relatively new to R, so I'm a bit stuck.

If someone could help help me with what is happening and what I should be doing next, I would appreciate any help.

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
0

There are 0 answers