Compute correlations with a target variable
compute_correlation.Rd
compute_correlation()
allows to compute correlation of several numerical
predictors with respect to a target variable. Optionally, the computation
can be done by groups.
Arguments
- data
A tibble.
- target_var
The variable against which the correlations needs to be computed. For instance,
dx_gap
.- by
A character vector.
- ...
Optional arguments passed to
correlate()
Examples
if (FALSE) {
tbl <-
build_tbl(
"tb",
year = NULL,
estimated = "who_estimates.e_inc_num",
notified = "who_notifications.c_newinc",
vars = extract_vars("tb")
) |>
dplyr::mutate(is_hbc = forcats::as_factor(is_hbc))
tbl |>
dplyr::filter(year == 2019) |>
compute_correlation(dx_gap, by = "year")
tbl |>
compute_correlation(dx_gap, by = c("year", "is_hbc"))
car_tbl <- tibble::as_tibble(mtcars, rownames = "car_name")
my_cars <- dplyr::select(car_tbl, -dplyr::all_of(c("vs", "am", "carb")))
compute_correlation(my_cars, mpg, by = c("gear", "cyl"))
compute_correlation(my_cars, mpg, by = NULL) # car_name is dropped by default
}