# NOT RUN {
require(tidyverse)
#Make a list of functions
f <-
list(
#Compute a univariate p-value
`P-value` =
function(x, y) {
if(type_match(y, c("factor", "character"))) {
p <- fisher.test(factor(x), factor(y), simulate.p.value = TRUE)$p.value
} else {
p <- kruskal.test(y, factor(x))$p.value
}
if_else(
p < 0.001, "<0.001", as.character(round(p, 2))
)
},
#Compute difference in AIC model between null model and one predictor model
`AIC Difference` =
function(x, y) {
glm(factor(x)~1, family = "binomial")$aic -
glm(factor(x)~y, family = "binomial")$aic
}
)
#1) Apply functions to Sex/HeartDisease by all other variables
heart_disease %>%
univariate_associations(
f = f,
responses = c("Sex", "HeartDisease")
)
#2) Only use two variables on RHS
heart_disease %>%
univariate_associations(
f = f,
responses = c("Sex", "HeartDisease"),
predictors = c("Age", "ChestPain")
)
#3) Use all combinations
heart_disease %>%
univariate_associations(
f = f
)
# }
Run the code above in your browser using DataLab