MIk: Calculates mutual information

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/MI_k.R

Description

Calculates mutual information for k categorical variables.

Usage

1
MIk(variables, data, smooth = 0, log_base = 2)

Arguments

variables

Vector of variable names.

data

Data frame or matrix with the variables.

smooth

Additional cell counts for bayesian estimation of probabilities.

log_base

The base of the logarithmic function to be used.

Details

The mutual information for variables V1,…,Vk is calculated by the formula

MI(V1,…,Vk) = ∑ P(V1,…,Vk) log(P (V1,…,Vk) / (P(V1)… P(Vk)))

where the sum is over all possible values of V1,…,Vk.

If the function is used for two variables it corresponds to using MI2 and for three variables it corresponds to MI3.

Value

The mutual information given by a single numeric value.

Author(s)

Katrine Kirkeby, enir_tak@hotmail.com

Maria Knudsen, mariaknudsen@hotmail.dk

Ninna Vihrs, ninnavihrs@hotmail.dk

References

\insertRef

EKTShyptcherry

See Also

MI2 and MI3 for mutual infomation for two or three variables respectively.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(43)
var1 <- c(sample(c(1, 2), 100, replace = TRUE))
var2 <- var1 + c(sample(c(1, 2), 100, replace = TRUE))
var3 <- var1 + c(sample(c(0, 1), 100, replace = TRUE,
                        prob = c(0.9, 0.1)))
var4 <- c(sample(c(1, 2), 100, replace = TRUE))
var5 <- var2 + var3
var6 <- var1 - var4 + c(sample(c(1, 2), 100, replace = TRUE))
var7 <- c(sample(c(1, 2), 100, replace = TRUE))

data <- data.frame("var1" = as.character(var1),
                   "var2" = as.character(var2),
                   "var3" = as.character(var3),
                   "var4" = as.character(var4),
                   "var5" = as.character(var5),
                   "var6" = as.character(var6),
                   "var7" = as.character(var7))
                   
MIk(c("var1", "var2", "var7"), data, smooth = 0.001)

nvihrs14/tcherry documentation built on Aug. 1, 2020, 6:25 p.m.