public static double regularisedBetaFunction(double z, double w, double x) {
		if (x < 0.0D || x > 1.0D) throw new IllegalArgumentException("Argument x, " + x + ", must be lie between 0 and 1 (inclusive)");
		double ibeta = 0.0D;
		if (x == 0.0D) {
			ibeta = 0.0D;
		} else {
			if (x == 1.0D) {
				ibeta = 1.0D;
			} else {
				// Term before continued fraction
				ibeta = Math.exp(Stat.logGamma(z + w) - Stat.logGamma(z) - logGamma(w) + z * Math.log(x) + w * Math.log(1.0D - x));
				// Continued fraction
				if (x < (z + 1.0D) / (z + w + 2.0D)) {
					ibeta = ibeta * Stat.contFract(z, w, x) / z;
				} else {
					// Use symmetry relationship
					ibeta = 1.0D - ibeta * Stat.contFract(w, z, 1.0D - x) / w;
				}
			}
		}
		return ibeta;
	}