Thread  RSS Function: limitSpikes()



# 11537 8 years ago on Sat, Jan 16 2016 at 10:29 pm

When displaying and working with statistical data, sometimes outliers can make the rest of your data almost invisible on certain types of line and bar charts.

I created a very quick and simple function in PHP to "clip" values that are above a certain number of times the average value of a data set:

function limitSpikes($d,$ceiling=4){ // Limits extreme values in a 1D array to no more than a ceiling multipler of the average value.
  $avg = ceil(array_sum($d) / count($d));
  foreach($d as $i => $v){
    $d[$i] = ($v > ($avg * $ceiling)) ? ($avg * $ceiling) : $v;
  }
  return $d;
}

Although it is quite basic, it does the job for line charts quite nicely.

73's, KD8FUD

User Image


Return to Index Return to topic list

Forgot password?
Currently Online
Users:0
Guests:26

Most Recently Online
Nitrocosm2 months ago
Lexica4 months ago
Wolfwood294 months ago
Miroku5 months ago
Doitsujin5 months ago