note 108615 deleted from function.stats-stat-correlation by salathe

From: Date: Fri, 11 May 2012 08:43:07 +0000
Subject: note 108615 deleted from function.stats-stat-correlation by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187930@lists.php.net to get a copy of this message
Note Submitter: 4705266 at gmail dot com ---- /***************************************\ ♫♪♫♪♫♥♪♫♪♪♫Fatih Mehmet DAĞ ♫♪♪♥♥♥♥♥♫♪♪ ♫♪♫♥♪♪♫♥♫♪♪ F.M.D. ♪♪♫♥♪♪♫♫♪♫♫ ♫♫♪♥♥♥♥♥♪♫♫4705266@gmail.com ♫♫♪♥♥♥♫♪♫♪♫ ♫♪♫♥♫♪♪♥♪♫♪www.fatihdag.com ♫♫♪♥♪♫♪♫♪♫♪ ♪♫♪♥♫♪♫♥♫♪♫11-05-2012 00:42:15♪♫♪♥♫♪♫♪♫♪♫ \***************************************/ function getCorrelation($x_array,$y_array){ //CODED by F.M.D $tx=0; $ty=0; $txy=0; $txx=0; $tyy=0; $n=count($x_array); foreach($x_array as $a=>$b){ $xy[]=$b*$y_array[$a]; $xx[]=$b*$b; $yy[]=$y_array[$a]*$y_array[$a]; $tx+=$b; $ty+=$y_array[$a]; $txy+=($b*$y_array[$a]); $txx+=($b*$b); $tyy+=($y_array[$a]*$y_array[$a]); } return (($n)*($txy)-($tx)*($ty))/sqrt((($n*$txx)-($tx*$tx) )*(($n*$tyy)-($ty*$ty))) ; } $x[]=60; $y[]=3.1; $x[]=61; $y[]=3.6; $x[]=62; $y[]=3.8; $x[]=63; $y[]=4; $x[]=65; $y[]=4.1; $r= getCorrelation($x,$y); echo "r^2 = $r"; output: r^2 = 0.91187249533773

« previous php.notes (#187930) next »