0

I need to conduct chi squared tests of association for quite a large amount of data of different characteristics at different sites between 2 years. For example, site 1 has 59 samples from 2019 and 82 samples from 2020. Each sample has a character with a value of either a or b. I have many characters and sites to analyse, so I wrote a function as follows:


library(chisq.posthoc.test)


char.function <- function(a19, a20, b19, b20, site.char) {
  
  site.char <- as.table(rbind(c(a19, a20), c(b19, b20)))
  dimnames(site.char) <- list(value = c("a", "b"), 
                              year = c("2019", "2020"))
  
  return(site.char)
  
  x <- chisq.test(site.char)
  y <- chisq.posthoc.test(site.char, method = "bonferroni")
  z <- chisq.posthoc.test(site.char, method = "fdr")
  
  return(x)
  return(y)
  return(z)
  
}

But when I call the function, for example:


char.function(3, 4, 56, 78, char.1)

It only returns the table like this:

     year
value 2019 2020
    a    3    4
    b   56   78

and not the results of the tests. How to I get it to return the results of the tests as well?

Thank you!

0 Answers0