Thread  RSS Function: limitSpikes()



# 11537 9 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:15

Most Recently Online
ZOL3 weeks ago
Wolfwood293 weeks ago
lam3 weeks ago
Nitrocosm1 month ago
Jovian1 month ago