Click here to Skip to main content
15,846,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
    require_once 'variance.php';
    require_once 'mean.php';

    function kurtosis($valArray, $isSample, $isExcess){
     $mean = mean($valArray);
        $variance = 0;
        $mult = 0;
        $moment4 = 0;
        $length = 0;

        foreach($valArray as $k => $moment4):
            $mult -= $mean;
            $mult *= $mult;
            $mult *= $mult;
            $moment4 += $mult;
            $length++;
        endforeach;
        $variance = variance($valArray, $mean, $isSample);
        $moment2 = ($variance *= $variance);
        $kurt = $length *($moment4 / $moment2);
        //normal kurtosis
        if((!$isSample) && (!$isExcess)):
            $kurtosis = $kurt;
            //excess kurtosis
        elseif(($isExcess) && (!$isSample)):
            $kurtosis = ($kurt - 3);
            // sample kurtosis
        elseif((!$isExcess) && ($isSample)):
            $n3 = ($length * $length * $length);
            $n2 = ($length * $length);
            $kurt = $n2 / $n3;
            $kurtosis = $kurt *($moment4 / $moment2);
            //sample excess kurtosis
        else:
            $n3 = ($length * $length * $length);
            $n2 = ($length * $length);
            $kurt = ( ($n2 / $n3) * ($moment4 / $moment2) );
            $kurtosis = $kurt - 3;
        endif;
        return $kurtosis;
    }
?>
Posted
Comments
NeverJustHere 19-Apr-14 17:23pm    
Inf possibly means you are performing a divide by zero somewhere in the calculation.

Since we don't have the data you are using, we cannot determine exactly where the error is.

I suggest you put some debugging code in to see what all the divisions are actually doing. Hopefully then, the issue will become clear to you.
Member 10287010 22-Apr-14 20:49pm    
thanks for the insight, i actually found out my error during the weekend. i was supposed to used moent4 where i had placed mult, and mult's value was 0.. but teaching me how to creat an array from database values would help with my current peril

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900