What you learn today
- Mean, range, deviation
- Detect outliers
Six temperature sensors in the greenhouse report 20, 21, 19, 20, 22 and 40 °C. The mean is 23.7 °C – and therefore wrong for every single corner. One of the sensors hangs next to the heater. Statistics show you how much a series of readings scatters and which value is out of line.
Mean, range, deviation
| Figure | calculation | tells |
|---|---|---|
| Mean | sum / count | where the values lie |
| Range | maximum − minimum | how far apart the extremes are |
| Standard deviation | square root of the mean of the squared distances from the mean | how much the values typically scatter |
The range is quick to compute but only reacts to the two extremes. The standard deviation (σ) takes every value into account.
Two passes
For σ you first need the mean and then each value's distance from it. The values are in the stack, so you go through twice:
pass2:
get value db i
sub value value mean # distance from the mean
mul value value value # squared
add total total value
add i i 1
blt i COUNT pass2
div dev total COUNT
sqrt dev dev
Dividing by the count gives the deviation of the series itself. For plants that is entirely sufficient.
Detecting outliers
A common rule of thumb: a value that lies more than two standard deviations from the mean is suspicious. For the six sensors above σ ≈ 7.4 °C. The 40 °C sensor lies 16.3 °C above the mean – more than 2 · 7.4. The others all lie below that.
sub value value mean
abs value value
sgt value value tmp # tmp = 2 · σ
add outl outl value
If all values are equal, σ = 0. Then any difference, however small, is “more than two deviations”. So check with sgt (strictly greater) and not with sge – with σ = 0 and equal values the distance stays 0 and does not count.
An outlier also skews the mean and σ themselves. If you need it precisely, compute a second time after removing the outliers. For a warning light the first pass is enough.
Diagram
Exercise
Task
Six readings are in v0 to v5 and are already put into the stack. Compute:
mean= averagerange= maximum − minimumdev= standard deviation (divide by the count)outl= number of values more than 2 ·devaway from the mean
Hints
Hint 1
First pass: sum, min and max. Then mean and range.
Hint 2
Second pass: square the distance from the mean and add up, divide by COUNT, sqrt.
Hint 3
Third pass: compare the abs of the distance with sgt against 2 · dev.
Quiz
4 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in