univariate_associations | R Documentation |
Evaluate a list
of scalar functions on any number of "response" columns by any number of "predictor" columns
univariate_associations( data, f, responses, predictors )
data |
A |
f |
A function or a |
responses |
A vector of quoted/unquoted columns, positions, and/or |
predictors |
A vector of quoted/unquoted columns, positions, and/or |
A tibble::tibble
with the response/predictor columns down the rows and the results of the f
across the columns. The names of the result columns will be the names provided in f
.
Alex Zajichek
#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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.