stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 299

Day 299 of 365 · Expert · Month 10: Bits and data

Statistics

Evaluating series of readings: mean, range and standard deviation in three passes, and outliers that lie more than two deviations away from the mean.

Lesson 20 min Week 43

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

Figurecalculationtells
Meansum / countwhere the values lie
Rangemaximum − minimumhow far apart the extremes are
Standard deviationsquare root of the mean of the squared distances from the meanhow 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
Warning

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.

Tip

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

The stack with its pointer slot 0 10 slot 1 20 slot 2 30 slot 3 slot 4 sp = 3 next free slot push 40 pop r0 r0 = 30 last in, first out
First the mean, then each value's distance from the mean – two passes over the same data.

Exercise

Task

Six readings are in v0 to v5 and are already put into the stack. Compute:

  • mean = average
  • range = maximum − minimum
  • dev = standard deviation (divide by the count)
  • outl = number of values more than 2 · dev away 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

Esc
↑ ↓ selectEnter open/ opens search anywhere