Biology, images, analysis, design...
Use/Abuse Principles How To Related
"It has long been an axiom of mine that the little things are infinitely the most important" (Sherlock Holmes)

Search this site



Just a note

For this set of data running medians give a similar picture to running means. This is because there are no clear cut outliers. If, however, there were a number of zero readings (for example when weather conditions were very adverse), the running medians would provide a more robust measure of population size.

The following code produces much the same sort of result using R.


  • Data are entered, and 2 x 2 plots established using the par(mfrow=2,2)) function.
  • For the first plot, plot(bfly,pch=20...) instructs R to plot out the points in order as a scatterplot.
  • The runmed function then enters 5-point running medians into variable z which are overplotted as lines using lines(z, col='blue'). This might appear to be a much simpler instruction than that for calculating a running mean, but is actually rather more sophisticated. In particular, it automatically allows for the ends of this run.

  • The second plot gives another 5-point running means plot for comparison. Notice that, although medians are unaffected by aberrant outlying points, a simple running median is noticeably less smooth than a running mean.

  • The third plot combines running medians and running means. meds=runmed(bfly,5) creates running medians in the variable meds.
  • These are then used to create running means with z[i] = (meds[i-2]+meds[i-1]+meds[i]+meds[i+1]+meds[i+2]) /5 }