note 100745 deleted from function.stats-stat-correlation by danbrown
| From: | danbrown@php.net | Date: | Thu, 04 Nov 2010 14:58:32 +0000 |
| Subject: | note 100745 deleted from function.stats-stat-correlation by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173752@lists.php.net to get a copy of this message | ||
Note Submitter: info at danielbaylis dot com
----
I received the undefined function error as well - I guess this belongs to some kind of extension
that must be installed.
Here is a single function I created to calculate r (Pearson's Correlation Coefficient). Arrays
must be equal length.
function getPearsons($array_x,$array_y)
{
if(sizeof($array_x) == sizeof($array_y))
{
$n = sizeof($array_x);
foreach($array_x as $key=>$val)
{
//Get the sum of the product of each pair
$sum_prod = $sum_prod + ($val * $array_y[$key]);
//Get the total of all values in each array
$sum_x = $sum_x + $val ;
$sum_y = $sum_y + $array_y[$key];
//Get the sum of squares for all values in each array
$ss_x = $ss_x + pow($val,2);
$ss_y = $ss_y + pow($array_y[$key],2);
}
$r = $sum_prod - (($sum_x*$sum_y) / $n);
$x = $ss_x - (pow($sum_x,2) / $n);
$y = $ss_y - (pow($sum_y,2) / $n);
$r = $r / sqrt($x*$y);
return $r;
}
}