10000) $samples=10000; if ($samples<12) $samples=12; if (!$query) $query = "disaster"; $df = $samples-1; $expected = $samples/2; for ($n=0; $n<$samples; $n++) { $coin = mt_rand(0,1); if($coin==1) $observed++;} $chi = ($observed-$expected)*($observed-$expected)/$expected; $p = p_chi($chi,$df); $minlog = number_format(log(1-$p,10),3); $paranormal = number_format((1-$p),40); $p = number_format($p,40); if($minlog=="inf") $minlog = "-infinite"; $news = file_get_contents("http://news.search.yahoo.com/news/search?p=$query"); preg_match ("/of about (.*?)<\/strong>/",$news,$count); if (!$count[1]) $count[1] = 0; function norm_p($z) { $z = abs($z); $a1 = 0.0000053830; $a2 = 0.0000488906; $a3 = 0.0000380036; $a4 = 0.0032776263; $a5 = 0.0211410061; $a6 = 0.0498673470; $p = ((((($a1*$z+$a2)*$z+$a3)*$z+$a4)*$z+$a5)*$z+$a6)*$z+1; $p = pow($p,-16); return($p);} function gfn($t) { if (abs(1-$t)<=0.1) { $g=0; for($j=1;$j<=5;$j++) { $g += 2*pow(1-$t,$j)/(($j+1)*($j+2));}} else { $g = (1-$t*$t+2*$t*log($t))/((1-$t)*(1-$t));} return($g);} function p_chi($chi,$df) { if ($chi<=0) { $p = 1;} else { $d = $chi-$df+2/3-0.08/$df; $g = gfn(($df-1)/$chi); $z = $d*sqrt((1+$g)/(2*$chi)); $p = norm_p($z)/2; if ($z<0) $p = 1-$p;} return($p);} echo " The Black Forest Box

The Black Forest Box

By Arduenn of The Black Forest

Yahoo News query:

Coin flips:

Expected heads: $expected

Observed heads: $observed

Chi-squared: $chi

Degrees of freedom: $df

p-value: $p

The chance that de difference between the amount of observed and expected heads is caused by a paranormal event is smaller than $paranormal ( < 10$minlog).

The number of news items containing the word '$query' found at news.yahoo.com: $count[1].

To be implemented: a prospective regression analysis between the p-value and the amount of news items for '$query'.
"; ?>