minfconf=function(x,y){ #this will spit out the quantiles of the MI from the bootstrap.. library(sm) air3 = cbind(x,y) result.12 = sm.density(air3, eval.points = air3, display = "none") result.1 = sm.density(x, eval.points = x, display = "none") result.2 = sm.density(y, eval.points = y, display = "none") #Mutual Information from the hand out.. #tobs = mean(log(result.12$estimate /(result.1$estimate * result.2$estimate))) #Average Mutual Information .. Moon et al. (1995) tobs = sum(result.12$estimate * log2(result.12$estimate /(result.1$estimate * result.2$estimate))) print(c(tobs)) n=length(x) nsim = 150 #500 bootstrap samples.. #vector of MI for the bootstrap samples.. simval = rep(0,nsim) #vector of correlations of the bootstrap samples.. simcor=rep(0,nsim) for (i in 1:nsim) { #sample y but not x. This disturbs the joint occurrence of x and y xy=sample(y,replace=TRUE) samp = cbind(y1 = x, y2 = xy) #to obtain confidence interval of MI both x and y are undisturbed. #xn=sample(1:n, replace=TRUE) # samp = cbind(y1 = x[xn], y2 = y[xn]) result.12 = sm.density(samp, eval.points = samp, display = "none") result.1 = sm.density(samp[,1], eval.points = samp[,1], display = "none") result.2 = sm.density(samp[,2], eval.points = samp[,2], display = "none") #Mutual Information from the hand out.. #simval[i] = mean(log(result.12$estimate /(result.1$estimate * result.2$estimate))) #Average Mutual Information .. Moon et al. (1995) simval[i] = sum(result.12$estimate * log2(result.12$estimate /(result.1$estimate * result.2$estimate))) simcor[i]=cor(samp[,1],samp[,2]) } quantile(simval,c(0.05,0.1,.50,.90,.95)) quantile(simcor,c(0.05,0.1,.50,.90,.95)) par(mfrow=c(1,2)) zz=boxplot(simcor,ylim=range(simcor,cor(x,y)),xlab="",ylab="Cor",plot=F) zz$names=rep("",length(zz$names)) z1=bxp(zz,xlab="",ylab="Cor",ylim=range(simcor,cor(x,y)), cex=1.25) points(z1, cor(x,y),cex=1.5,pch=16) title(main="Boxplot of bootstrap correlations") zz=boxplot(simval,ylim=range(simval,tobs),xlab="",ylab="MI",plot=F) zz$names=rep("",length(zz$names)) z1=bxp(zz,xlab="",ylab="MI",ylim=range(simval,tobs),cex=1.25) points(z1, tobs,cex=1.5,pch=16) title(main="Boxplot of bootstrap MI") }