/* unconditional mutual information, to be used for the asymptotic test. */ SEXP mi(SEXP x, SEXP y, SEXP gsquare) { int llx = NLEVELS(x), lly = NLEVELS(y), num = LENGTH(x); int *xx = INTEGER(x), *yy = INTEGER(y); double *res = NULL; SEXP result; PROTECT(result = allocVector(REALSXP, 2)); res = REAL(result); res[0] = c_mi(xx, &llx, yy, &lly, &num); res[1] = (double)(llx - 1) * (double)(lly - 1); /* rescale to match the G^2 test. */ if (isTRUE(gsquare)) res[0] *= 2 * num; UNPROTECT(1); return result; }/*MI*/
/* compute all the pairwise mutual information coefficients between the variables. */ void mi_matrix(double *mim, void **columns, int dim, int *nlevels, int *num, void *cond, int *clevels, int *est) { int i = 0, j = 0; switch(*est) { case DISCRETE_MAXIMUM_LIKELIHOOD: if (cond == NULL) { for (i = 0; i < dim; i++) { for (j = i + 1; j < dim; j++) { mim[UPTRI3(i + 1, j + 1, dim)] = c_mi(((int **)columns)[i], nlevels + i, ((int **)columns)[j], nlevels + j, num); }/*FOR*/ }/*FOR*/ }/*THEN*/ else { for (i = 0; i < dim; i++) { for (j = i + 1; j < dim; j++) { mim[UPTRI3(i + 1, j + 1, dim)] = c_cmi(((int **)columns)[i], nlevels + i, ((int **)columns)[j], nlevels + j, (int *)cond, clevels, num); }/*FOR*/ }/*FOR*/ }/*ELSE*/ break; case GAUSSIAN_MAXIMUM_LIKELIHOOD: for (i = 0; i < dim; i++) { for (j = i + 1; j < dim; j++) { mim[UPTRI3(i + 1, j + 1, dim)] = c_mig(((double **)columns)[i], ((double **)columns)[j], num); }/*FOR*/ }/*FOR*/ break; }/*SWITCH*/ }/*MI_MATRIX*/