0

私が使用しているコードは次のとおりです。

<?php
function Median($dataPoints) {
    return Quartile_50($dataPoints);
}

function Quartile_25($dataPoints) {
    return Quartile($dataPoints, 0.25);
}

function Quartile_50($dataPoints) {
    return Quartile($dataPoints, 0.5);
}

function Quartile_75($dataPoints) {
    return Quartile($dataPoints, 0.75);
}

function Quartile($dataPoints, $Quartile) {
    sort($dataPoints);
    $pos = (count($dataPoints)-1) * $Quartile;

    $base = floor($pos);
    $rest = $pos - $base;

    if( isset($dataPoints[$base+1]) ) {
        return $dataPoints[$base] + $rest * ($dataPoints[$base+1] - $dataPoints[$base]);
    } else {
        return $dataPoints[$base];
    }
}

function Average($dataPoints) {
    return array_sum($dataPoints)/ count($dataPoints);
}

function StdDev($dataPoints) {
    if(count($dataPoints) < 2) {
        return;
    }
    $avg = Average($dataPoints);

    $sum = 0;
    foreach($dataPoints as $value) {
        $sum += pow($value - $avg, 2);
    }
    return sqrt((1/(count($dataPoints)-1))*$sum);
}

そして、ここに私が受け取っているエラーがあります:

Fatal error: Uncaught Error: Unsupported operand types in C:\xampp\htdocs\arraytest.php:62 スタック トレース: #0 C:\xampp\htdocs\arraytest.php(45): Quartile(Array, 0.25) #1 C :\xampp\htdocs\arraytest.php(84): Quartile_25(Array) #2 {main} が C:\xampp\htdocs\arraytest.php 行 62 でスローされました

62行目は次のとおりです。

return $dataPoints[$base] + $rest * ($dataPoints[$base+1] - $dataPoints[$base]);

$dataPointsは私の配列なので、2つの配列を減算できなかったからだと思いました。減算関数を に置き換えたときに、まだエラーが発生しましたarray_diff()。Quartile() 関数を正しく入力していますか?

助けてくれてありがとう

4

0 に答える 0