Skip to content

Instantly share code, notes, and snippets.

@hrstt
Last active November 29, 2019 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrstt/629f17c3a5b6680bad35c871557d2bf5 to your computer and use it in GitHub Desktop.
Save hrstt/629f17c3a5b6680bad35c871557d2bf5 to your computer and use it in GitHub Desktop.
for chisq.test, convert count data to matrix with tidyverse
library(tidyverse)
tidyToChisq <- function(data, col, row) {
return(
data %>% group_by_(col, row) %>%
summarise(count = n()) %>% spread(row, count, fill = 0) %>%
ungroup() %>% select(-starts_with(col)) %>% as.matrix() %>% chisq.test())
}
@hrstt
Copy link
Author

hrstt commented Nov 29, 2019

chisq.test()のオプション類はデフォルト値で。引数で指定するオプションがない簡易版。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment