Learn R Programming

tidyinftheo (version 0.2.1)

mutual_info: Mutual information MI(X;Y) = H(X) - H(X|Y) = H(Y) - H(Y|X)

Description

This calculates the mutual information between two variables in a tibble. (if normalized). It's assumed these columns are character typed with no NAs.

Usage

mutual_info(.data, ..., normalized = FALSE, na.rm = FALSE)

Arguments

.data

A tibble with the column of interest

...

two columns (variables) selected

normalized

if TRUE, scale from 0 to 1

na.rm

remove all rows with NA values in at least one of the columns

Value

a double with the calculated value

Examples

Run this code
# NOT RUN {
# make an all-character version of mtchars
mt_tib <- as_tibble(mtcars) %>% mutate_all(as.character)
mutual_info(mt_tib, vs, am)
mutual_info(mt_tib, 'am', 'vs')
mutual_info(mt_tib, vs, am, normalized=TRUE)
mutual_info(mt_tib, starts_with('c'))
# }

Run the code above in your browser using DataLab