#Make a list of functions to evaluate
f <-
list(
#Compute a univariate p-value
`P-value` =
function(y, x) {
if(some_type(x, c("factor", "character"))) {
p <- fisher.test(factor(y), factor(x), simulate.p.value = TRUE)$p.value
} else {
p <- kruskal.test(x, factor(y))$p.value
}
ifelse(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(y, x) {
glm(factor(y)~1, family = "binomial")$aic -
glm(factor(y)~x, family = "binomial")$aic
}
)
#Choose a couple binary outcomes
heart_disease %>%
univariate_associations(
f = f,
responses = c(ExerciseInducedAngina, HeartDisease)
)
#Use a subset of predictors
heart_disease %>%
univariate_associations(
f = f,
responses = c(ExerciseInducedAngina, HeartDisease),
predictors = c(Age, BP)
)
#Numeric predictors only
heart_disease %>%
univariate_associations(
f = f,
responses = c(ExerciseInducedAngina, HeartDisease),
predictors = is.numeric
)
Run the code above in your browser using DataLab