Created
April 4, 2018 07:03
-
-
Save gdmcdonald/1023f313a2534fee979fb6a9fc868edf to your computer and use it in GitHub Desktop.
An example of using normalised mutual information in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load the mutual information library | |
library(mpmi) | |
#define normalised continuous mutual information, bias corrected | |
ncmi<-function(cts,...){ | |
MIunnorm<-cmi(cts,...) | |
MIbcmiself<-diag(MIunnorm$bcmi) | |
MIbcminorm<-outer(MIbcmiself,MIbcmiself,FUN = "*") | |
MInormed<-MIunnorm$bcmi / sqrt(MIbcminorm) | |
colnames(MInormed)<-colnames(cts) | |
return(MInormed) | |
} | |
#look at an iris example usage with corrplot | |
library(tidyverse) | |
library(corrplot) | |
iris.measurements<-iris%>% | |
dplyr::select(1:4)%>% | |
na.omit() | |
corrplot.mixed(ncmi(iris.measurements), | |
cl.lim = c(0,1), | |
title = "Normalised Mutual Information between Iris dimensions", | |
mar=c(0,0,1,0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment