Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created February 10, 2017 01:48
Show Gist options
  • Save Keiku/40e3cf1a1fb3962222d5bd25649fae21 to your computer and use it in GitHub Desktop.
Save Keiku/40e3cf1a1fb3962222d5bd25649fae21 to your computer and use it in GitHub Desktop.
Chi-square testing in each group.
library(dplyr)
library(purrr)
library(broom)
df <- data_frame(
group = rep(letters[1:2], each = 50),
cat1 = letters[round(runif(100) * 5) + 1],
cat2 = letters[round(runif(100) * 3) + 1]
)
df %>%
split(.$group) %>%
map(~chisq.test(.$cat1, .$cat2, simulate.p.value = TRUE, B = 10)) %>%
map_df(glance)
# statistic p.value parameter
# 1 14.69461 0.6363636 NA
# 2 15.23163 0.6363636 NA
# method
# 1 Pearson's Chi-squared test with simulated p-value\n\t (based on 10 replicates)
# 2 Pearson's Chi-squared test with simulated p-value\n\t (based on 10 replicates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment