There is an array of data with numeric values. It is necessary to determine the arithmetic average, but weed out the values ​​that differ greatly in the higher or lower side from the majority.

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants cheops , aleksandr barakin , Kirill Stoianov , Streletz , Denis Sep 27 '16 at 6:49 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Think mate. waiting and variance on the initial array. Further, depending on your criteria, which are not very different from the average, take only those elements of the array that lie in the mat range. waiting + - (1 or 2 or 3) * variance. Then consider the mat. waiting for a new array. - ArchDemon
  • @ArchDemon Thank you very much for the answer. But I still can not use it. Example. [1, 8, 10, 12, 15]. Obviously here it is necessary to discard [1]. Mat. expectation = 9.2; Dispersion: 22.16; The range with multiplier 1 is from +31.36 to -12.96. Reduced the multiplier to 0.3; the range was from +15.84 to 4.76. [1] dropped out But how to determine this factor for random numbers? - serken
  • I think to do as follows. Divide the standard deviation on the mat. expectation and multiply by 100. Get the coefficient of variation. If the result is less than 33% then find a value that differs more than others from the mat. waiting and dropping it. Repeat until the ratio is <33%. - serken September

1 answer 1

@ArchDemon
Thank you for responding.

function findElse ( $arrArg=[] ) { $fixsion = $arrArg; $sum = 0; $i=0; $koef = 100; foreach ($fixsion as $key => $value) { $disp += pow ($value, 2); $sum += $value; $i++; }; $sum = $sum/$i; $disp = ($disp/$i) - pow ($sum, 2); $koef = ( sqrt ($disp) / $sum )*100; if ($koef>33) { foreach ($fixsion as $key => $value) { if ( abs ($sum - $value)>$max) { $max = abs ($sum - $value); $maxId = $key; }; }; unset( $fixsion[$maxId] ); $fixsion = array_values($fixsion); findElse ( $fixsion ); }; return $fixsion; }; 
  • I lied to you a little. Indeed, a large variance is obtained. It is necessary to count not it, but the standard deviation (sko). And already take mat. waiting + - (1 or 2 or 3) * sc - ArchDemon