I cant figure out how to do a chi- squared test with this table

Hi, as part of my results for my dissertation i have made this table comparing the number of generalist and specialist bird species according to different habitats (Just in case the image is not clear, i have drawn a rough copy below):

Habitat type Generalists Specialists
Grazed grassland 8 1
Non-grazed grassland 6 11
Forest 7 8

I am trying to carry out a chi-squared test to see if the number of each species type is related to habitat type, however, because of the multiple columns i cannot figure out how to do it

would anyone be able to help with this?

The chisq.test function seems to expect a matrix or vectors, so I would do the test like this:

MAT <- matrix(c(8,6,7,1,11,8), nrow = 3)
dimnames(MAT) <- list(c("Grazed", "Non-grazed", "Forest"), 
                      c("Generalists", "Specialists"))
#>            Generalists Specialists
#> Grazed               8           1
#> Non-grazed           6          11
#> Forest               7           8
#> Warning in chisq.test(MAT): Chi-squared approximation may be incorrect
#>  Pearson's Chi-squared test
#> data:  MAT
#> X-squared = 6.9615, df = 2, p-value = 0.03079

Created on 2023-11-08 with reprex v2.0.2

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.