Calculate the average without throwing it away

I am trying to calculate the average without throwing away a small number of distant numbers (i.e. 1,2,1,2,3,4,50), one 50 will throw off the whole average.

If I have a list of numbers like this:

19,20,21,21,22,30,60,60

Average value 31

Median 30

The mode is 21 and 60 (averaged to 40.5 )

But everyone can see that most are in the range 19-22 (5 inches, 3 outputs), and if you get an average of only the main range of 20.6 (a big difference than any number above)

I think you can get it like this:

c + dr

c - , d - , r - . , - , .

, 19,20,21,21,22 5 , 4 , 3 (22 - 19). , 5 + 4-3 = 6

, 8 + 6-41 = -27

, , . 21 :

<19 > 19-19, 19-20, 19-21, 19-22, 19-30, 19-60, 20-20, 20-21, 20-22, 20-30, 20-60, 21-21, 21-22, 21-30, 21-60, 22-22, 22-30, 22-60, 30-30, 30-60, 60-60

, .

, - ?

+5
5

, , . outlier , 1 ( , ) , , .

+2

, . . , , .

function get_median($arr) {
    sort($arr);
    $c = count($arr) - 1;
    if ($c%2) {
        $b = round($c/2);
        $a = $b-1;
        return ($arr[$b] + $arr[$a]) / 2 ;
    } else {
        return $arr[($c/2)];
    }
}

function get_five_number_summary($arr) {
    sort($arr);
    $c = count($arr) - 1;
    $fns = array();
    if ($c%2) {
        $b = round($c/2);
        $a = $b-1;
        $lower_quartile = array_slice($arr, 1, $a-1);
        $upper_quartile = array_slice($arr, $b+1, count($lower_quartile));
        $fns = array($arr[0], get_median($lower_quartile), get_median($arr), get_median($upper_quartile), $arr[$c-1]);
        return $fns;
    }
    else {
        $b = round($c/2);
        $a = $b-1;
        $lower_quartile = array_slice($arr, 1, $a);
        $upper_quartile = array_slice($arr, $b+1, count($lower_quartile));
        $fns = array($arr[0], get_median($lower_quartile), get_median($arr), get_median($upper_quartile), $arr[$c-1]);
        return $fns;
    }
}

function find_outliers($arr) {
    $fns = get_five_number_summary($arr);
    $interquartile_range = $fns[3] - $fns[1];
    $low = $fns[1] - $interquartile_range;
    $high = $fns[3] + $interquartile_range;
    foreach ($arr as $v) {
        if ($v > $high || $v < $low)
            echo "$v is an outlier<br>";
    }
}

//$numbers = array( 19,20,21,21,22,30,60 ); // 60 is an outlier
$numbers = array( 1,230,239,331,340,800); // 1 is an outlier, 800 is an outlier
find_outliers($numbers);

, , , , 60 , . , , !

, , : http://www.mathwords.com/o/outlier.htm

, , , find_outliers(): P

+2

? 30, 21.5.

+1

, , median, , , , , .

0

, (, 90%) .

, , (, ). , , , .

0

All Articles