# total counts of true situations, and P(x): Counts <- c(742, 1118, 752, 1802, 1231, 1001) Total <- sum(Counts) PX <- Counts/Total # Confusion matrix counts Cconfusion <- rbind (c(41, 93, 29, 186, 294, 99), c(8, 824, 2, 151, 66, 67), c(30, 50, 110, 321, 120, 121), c(13, 233, 72, 1131, 112, 241), c(139,136, 66, 373, 365, 152), c(20, 73, 50, 378, 116, 364)) # Joint probabilities -- P(x,y) PXY <- Cconfusion/Total # counts by response type, and P(y): ResponseCounts <- apply(Cconfusion,2,sum) PY <- ResponseCounts/Total # Mutual Information: MI <- 0 for (n in 1:6){ for(m in 1:6){ MI = MI + PXY[n,m]*log2(PXY[n,m]/(PX[n]*PY[m])) } }