public static double chiSquare(double[] observed, double[] expected, double[] variance) {
		int nObs = observed.length;
		int nExp = expected.length;
		int nVar = variance.length;
		if (nObs != nExp) throw new IllegalArgumentException("observed array length does not equal the expected array length");
		if (nObs != nVar) throw new IllegalArgumentException("observed array length does not equal the variance array length");
		double chi = 0.0D;
		for (int i = 0; i < nObs; i++) {
			chi += Fmath.square(observed[i] - expected[i]) / variance[i];
		}
		return chi;
	}