z-Scores(standard deviation and mean) in PHP

前端 未结 5 1548
暖寄归人
暖寄归人 2020-12-05 14:47

I am trying to calculate Z-scores using PHP. Essentially, I am looking for the most efficient way to calculate the mean and standard deviation of a data set (PHP array). Any

5条回答
  •  半阙折子戏
    2020-12-05 15:21

       function standard_deviation($aValues)
    {
        $fMean = array_sum($aValues) / count($aValues);
        //print_r($fMean);
        $fVariance = 0.0;
        foreach ($aValues as $i)
        {
            $fVariance += pow($i - $fMean, 2);
    
        }       
        $size = count($aValues) - 1;
        return (float) sqrt($fVariance)/sqrt($size);
    }
    

提交回复
热议问题