Created
October 26, 2023 01:49
-
-
Save bschneidr/f36ae41255a956be02bf1e4ec4e65dae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(broom) | |
library(tidyr) | |
# Make example data | |
my_data <- data.frame(x = sample(1:5, size = 10, replace = TRUE), | |
y = sample(1:5, size = 10, replace = TRUE)) | |
# Generate every pair of variables | |
var_list <- colnames(my_data) | |
var_combinations <- expand.grid(Var_1 = var_list, Var_2 = var_list, | |
stringsAsFactors = FALSE) | |
var_combinations |> | |
# Group data by rows | |
rowwise() |> | |
# Do a Chi-square test and tidy the output | |
mutate( | |
chisq_test = chisq.test(x = my_data[[Var_1]], | |
y = my_data[[Var_2]]) |> | |
broom::tidy() | |
) |> | |
unnest(cols = chisq_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment