double ContingencyTable_cramersStatistic (ContingencyTable me) {
	double chisq, sum = 0;
	long df, nr = my numberOfRows, nc = my numberOfColumns, nmin = nr;

	if (nr == 1 || nc == 1) {
		return 0;
	}

	for (long i = 1; i <= nr; i++) {
		for (long j = 1; j <= nc; j++) {
			sum += my data[i][j];
		}
	}

	if (nc < nr) {
		nmin = nc;
	}
	nmin--;

	ContingencyTable_chisq (me, &chisq, &df);
	if (chisq == 0 && df == 0) {
		return 0;
	}
	return sqrt (chisq / (sum * nmin));
}
Beispiel #2
0
double ContingencyTable_chisqProbability (ContingencyTable me) {
	double chisq, df;
	ContingencyTable_chisq (me, &chisq, &df);
	if (chisq == 0.0 && df == 0.0) {
		return 0.0;
	}
	return NUMchiSquareQ (chisq, df);
}
double ContingencyTable_contingencyCoefficient (ContingencyTable me) {
	double chisq, sum = 0;
	long df, nr = my numberOfRows, nc = my numberOfColumns;

	for (long i = 1; i <= nr; i++) {
		for (long j = 1; j <= nc; j++) {
			sum += my data[i][j];
		}
	}

	ContingencyTable_chisq (me, &chisq, &df);
	if (chisq == 0 && df == 0) {
		return 0;
	}
	return sqrt (chisq / (chisq + sum));
}
void structContingencyTable :: v_info () {
	structData :: v_info ();

	long ndf;
	double h, hx, hy, hygx, hxgy, uygx, uxgy, uxy, chisq;
	ContingencyTable_entropies (this, &h, &hx, &hy, &hygx, &hxgy, &uygx, &uxgy, &uxy);
	ContingencyTable_chisq (this, &chisq, &ndf);

	Melder_information (L"Number of rows: ", Melder_integer (numberOfRows));
	Melder_information (L"Number of columns: ", Melder_integer (numberOfColumns));
	Melder_information (L"Entropies (y is row variable):");
	Melder_information (L"  Total: ", Melder_double (h));
	Melder_information (L"  Y: ", Melder_double (hy));
	Melder_information (L"  X: ", Melder_double (hx));
	Melder_information (L"  Y given x: ", Melder_double (hygx));
	Melder_information (L"  X given y: ", Melder_double (hxgy));
	Melder_information (L"  Dependency of y on x: ", Melder_double (uygx));
	Melder_information (L"  Dependency of x on y: ", Melder_double (uxgy));
	Melder_information (L"  Symmetrical dependency: ", Melder_double (uxy));
	Melder_information (L"  Chi squared: ", Melder_double (chisq));
	Melder_information (L"  Degrees of freedom: ", Melder_integer (ndf));
	Melder_information (L"  Probability: ", Melder_double (ContingencyTable_chisqProbability (this)));
}
Beispiel #5
0
void structContingencyTable :: v_info () {
	structDaata :: v_info ();

	double ndf;
	double h, hx, hy, hygx, hxgy, uygx, uxgy, uxy, chisq;
	ContingencyTable_entropies (this, &h, &hx, &hy, &hygx, &hxgy, &uygx, &uxgy, &uxy);
	ContingencyTable_chisq (this, &chisq, &ndf);

	MelderInfo_writeLine (U"Number of rows: ", numberOfRows);
	MelderInfo_writeLine (U"Number of columns: ", numberOfColumns);
	MelderInfo_writeLine (U"Entropies (y is row variable):");
	MelderInfo_writeLine (U"  Total: ", h);
	MelderInfo_writeLine (U"  Y: ", hy);
	MelderInfo_writeLine (U"  X: ", hx);
	MelderInfo_writeLine (U"  Y given x: ", hygx);
	MelderInfo_writeLine (U"  X given y: ", hxgy);
	MelderInfo_writeLine (U"  Dependency of y on x: ", uygx);
	MelderInfo_writeLine (U"  Dependency of x on y: ", uxgy);
	MelderInfo_writeLine (U"  Symmetrical dependency: ", uxy);
	MelderInfo_writeLine (U"  Chi squared: ", chisq);
	MelderInfo_writeLine (U"  Degrees of freedom: ", ndf);
	MelderInfo_writeLine (U"  Probability: ", ContingencyTable_chisqProbability (this));
}