minfnormalconf=function(x,y){ #this will spit out the quantiles of the MI estimated using # a bivariate normal PDF for the bootstrap samples.. library(mvtnorm) library(akima) air3 = cbind(x,y) x=air3[,1] y=air3[,2] result.12 = dmvnorm(air3, mean=colMeans(air3), sigma=var(air3)) result.1=dnorm(x,mean=mean(x), sd=sd(x)) result.2=dnorm(y,mean=mean(y), sd=sd(y)) #Average Mutual Information .. Moon et al. (1995) tobs = sum(result.12 * log2(result.12 /(result.1 * result.2))) print(c(tobs)) n=length(x) #500 bootstrap samples.. nsim = 500 #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 # you can do the other way as well.. xy=sample(y,replace=TRUE) samp = cbind(y1 = x, y2 = xy) x1=samp[,1] y1=samp[,2] #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 = dmvnorm(samp, mean=colMeans(samp), sigma=var(samp)) result.1=dnorm(x1,mean=mean(x1), sd=sd(x1)) result.2=dnorm(y1,mean=mean(y1), sd=sd(y1)) #Average Mutual Information .. Moon et al. (1995) simval[i] = sum(result.12 * log2(result.12 /(result.1 * result.2))) #Correlation 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=myboxplot(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=myboxplot(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 from Normal PDFs") }