binomnom

Download:

#!/usr/bin/php
<?php
function binomial_coefficient($n, $m) {
	$j = 1;
	$res = 1;
	if($m < 0 || $m > $n){
		return 0;
		}
	if(($n - $m) < $m){
		$m = $n - $m;
		}
	while($j <= $m) {
		$res *= $n--;
		$res /= $j++;
		}
	return $res;
	}

define('ALPHA', 5.0);		//significance niveau
define('TEST_RESULT', 39);	//result of measurement
define('METHOD', "totheright");	//method totheright|totheleft

$n = 76;	//total probes
$k = 10 / 3;		//possibilities per probe
//$m = 20;	//number of results
$r = 1;		//possibilities per result
$p = $r / $k;		//probability for each result

$pvalue_r = 0.0;
$pvalue_l = 0.0;
$pvalue_b = 0.0;
$Pnm_last = 0.0;
$average = false;
$alpha = false;
$test_result = false;

echo "Probabilities\r\nof\t\tn = ".$n." samples\r\nwidth\tk = ".$k." options\r\nto hit\tm = ".TEST_RESULT." times\r\nwith\tr = ".$r." alternative/s\r\nusing\t".METHOD." method\r\nat\t\talpha = ".ALPHA."% significance niveau\r\n\r\n";

for ($m = 0; $m <= $n; $m++){
	$Pnm = binomial_coefficient($n, $m) * pow($p, $m) * pow((1 - $p), ($n - $m));
	$Pnm = round($Pnm * 100, 4);

	echo "n = ";
	echo sprintf("%02d", $m);
	echo " -> binom. coeff. = ";
	echo sprintf("%011d", binomial_coefficient($n, $m));
	echo " -> P = ";
	echo sprintf("%02d", floor($Pnm));
	echo ".";
	echo ($Pnm > 0) ? substr($Pnm - floor($Pnm), 2) : "0000";
	echo "% ";
	if ($m < TEST_RESULT){
		echo "- ";
		}
	if ($m > TEST_RESULT){
		echo "+ ";
		}
	if ($m == TEST_RESULT){
		echo "o ";
		}
	for ($dr = 1; $dr <= round($Pnm*4, 0); $dr++){
		echo "#";
		}
	if ($m >= TEST_RESULT && $test_result === false){
		$test_result = true;
		echo " <- test result";
		}
	if ($Pnm > 0 && $Pnm <= $Pnm_last && $average === false){
		$average = true;
		echo " <- median probability";
		}
	if ($Pnm > 0 && $Pnm <= $Pnm_last && $Pnm <= ALPHA && $alpha === false){
		$alpha = true;
		echo " <- alpha";
		}
	echo "\r\n";

	if ($Pnm > 0 && $m >= TEST_RESULT){		//Method 'to the right'
		$pvalue_r = $pvalue_r + $Pnm;
		}
	if ($Pnm > 0 && $m <= TEST_RESULT){		//Method 'to the left'
		$pvalue_l = $pvalue_l + $Pnm;
		}
	$Pnm_last = $Pnm;
	}
echo "\r\n";
switch (METHOD){
	case "totheleft":
		echo "p-value for n = ".TEST_RESULT." (to the left) = ".$pvalue_l."%\r\n";
		break;
	case "totheright":
		echo "p-value for n = ".TEST_RESULT." (to the right) = ".$pvalue_r."%\r\n";
		break;
	default:
		break;
	}
?>

documentation.txt -> unavailable, yet. Please be patient.
license.txt

This product includes/requires PHP software, freely available from
http://www.php.net/software/

<<< back