Individuals chart
The constant
A technician who is called to site for every high reading soon stops answering, and then the one reading that mattered is missed. A manager who sees one low energy day claims a saving, and the next week it has gone. Both people lack the same thing: a rule that says how far a reading moves when nothing has changed. A control chart is that rule, drawn on the readings themselves. This lesson shows how to set its limits from your own data, how often it will give a false alarm, and how to find a small change that no single reading shows. #ControlCharts #EWMA #ProcessMonitoring
By the end of this lesson, you will be able to:
A building used 742 kWh yesterday and 498 kWh the day before. Nobody can say from these two numbers whether anything is wrong. Yesterday was a hot working day and the day before was a Sunday. The energy of a building moves every day with the weather and the calendar, and a little more for reasons that nobody will ever trace.
The site has a second question. An energy-saving measure was installed on day 500 of the record. The supplier says it saves 12 percent. A change of 12 percent is smaller than the difference between a Sunday and a Monday, so no single day will show it. The owner wants to know on which day the data alone would have shown that something changed.
Both questions need the same two steps. First remove the part of the movement that has a known driver, with a baseline model. Then put what remains on a chart whose limits say how large the unexplained movement normally is.
Every measured process moves. The movement that is always present, from many small causes that nobody can separate, is called common cause variation. A process that shows only this movement is called stable, or in control. Its next value cannot be predicted exactly, but the range in which it will fall can be.
A special cause is something that was not there before: a door seal that failed, a compressor that tripped, a setpoint that somebody changed, a saving measure that was installed. A special cause is worth a visit. Common cause variation is not.
A control chart is a time plot of the readings with three horizontal lines: a centre line at the mean, and an upper and a lower control limit three standard deviations from it. A point outside the limits is a signal that a special cause is likely.
When there is one value for each period (one daily mean, one daily energy), the chart is called an individuals chart. Its centre line is the sample mean
The standard deviation is not taken from the usual formula for
For independent normal readings, the mean range of two readings is
Individuals chart
The constant
The moving range is used because it looks only at neighbours. If the mean shifted once during the period,
A cold room for vaccines must stay between 2 °C and 8 °C. Those are specification limits, what the product needs; control limits say what the room normally does.
If the room normally gives daily means between 3.99 °C and 4.04 °C, a daily mean of 4.5 °C is far inside the specification and is also a clear sign that something changed. A chart with the specification drawn as its limits would stay silent until the stock was already at risk.
For independent readings with a normal distribution, 99.73 percent of the values lie within three standard deviations of the mean. So a stable process still puts about 0.27 percent of its points outside the limits, which is about one point in 370. With one point a day, expect one false alarm a year. With one point a minute, expect about four a day.
Many sensors multiply this. A site with 50 daily charts has a chance of
That rate is true only for independent readings. Sensor readings taken close together are not independent: each one is near the one before it. This is autocorrelation, and it damages the chart in a specific way. Neighbouring readings differ very little, so the mean moving range is small and the limits are narrow. But over an hour the reading travels much further than it does between neighbours, so it leaves those narrow limits again and again.
A sustained small shift can leave every point inside the limits and still show itself by a pattern. Extra rules, called run rules, look for such patterns. This lesson uses two rules:
The second rule works because a stable process puts each point above or below the centre line with a chance of one half, like a coin. Eight on one side by chance has a probability of
Textbooks list more rules. Each added rule finds some real changes sooner and adds its own false alarms: the two rules above together give a false alarm about once in 151 points of a stable process, not once in 370. Use few rules, and say which ones you used.
The individuals chart judges each point alone and forgets it; to find a small shift, a chart must remember. The exponentially weighted moving average (EWMA) does this:
Here
Because
EWMA chart, steady-state limits
These limits are the steady-state form. For the first few points the exact limits are a little narrower.
The EWMA has a cost: it reacts late to one large sudden value, which enters with a weight of only
The average run length (ARL) puts numbers on this: the mean number of points from the start of a shift to the first signal. With no shift, it is the mean number of points between false alarms. For independent normal readings:
| Shift, in standard deviations | Individuals chart, 3-sigma | EWMA, |
|---|---|---|
| 0 (false alarms) | 370 | 560 |
| 0.5 | 155 | 44 |
| 1 | 44 | 10.8 |
| 2 | 6.3 | 3.8 |
The EWMA gives fewer false alarms and finds a shift of half a standard deviation more than three times sooner. For a shift of two standard deviations the two charts are close.
A control chart assumes that the mean of a stable process is constant. Daily energy does not: it rises in the hot season and falls every weekend, so a chart of raw energy signals the weather and the calendar, which you already know about.
The cure is to chart the residual of a baseline model:
The baseline removes what the weather and the weekday explain. What remains has a mean of zero while the building behaves as it did in the baseline period, and a mean different from zero when the building itself has changed.
A signal is a reason to look, not a proof. The reverse also holds: a sensor that stops sending, or repeats one value, keeps its chart quiet. Give every charted sensor a separate alarm for missing or frozen data, or the quiet chart will be read as a healthy machine.
Centre line. The mean of the 14 daily means is
Moving ranges. There are 13 differences between neighbouring days. The first is
The printed three-decimal values give 0.0096, which is the same within rounding. ✅
Standard deviation.
Limits.
The lower limit is
Points beyond the limits. Day 0, at
Is day 0 a special cause? Nothing in the log explains it. With no cause found, the point is marked as unexplained and it stays in the data. ✅
Check the assumption behind the limits. The ordinary standard deviation of the 14 means is
Judge the limits honestly. Textbooks ask for 20 to 25 points or more before limits are trusted. With 14 points these limits are provisional. They are used below, and should be recalculated once a month of normal days exists. ✅
Rise. In 60 minutes with the compressor off the air rises by
Recovery. The compressor removes that rise in
Amount added to the day’s mean. The area of the triangle is spread over the 1440 minutes of the day.
The mean of day 10 becomes
Does the chart signal?
Shortest hold the chart detects. For a hold of
A hold of 25 minutes or more on day 10 is detected. During a 25 minute hold the air rises by only 2.5 °C. ✅
Include the disturbed day in the limits. This is the mistake of calculating limits from a period that was not normal. The mean moving range grows from 0.00968 to 0.0353, and the limits become
Result. Day 10 at
The same chart on raw readings. The script reproduces the hand values above. It also puts the 20,160 minute readings on an individuals chart: 60.8 percent of them are beyond the limits. On the 336 hourly means, 7 points (2.1 percent) are beyond the limits, about eight times the 0.27 percent of independent readings. ✅
Least squares on days 0 to 364.
The base load is 306.6 kWh a day, each cooling degree day adds 41.61 kWh, and a working day adds 182.1 kWh. ✅
Quality of the fit. With
Residuals. For every one of the 730 days, residual = actual minus predicted. In the baseline period their mean is 0.00 kWh, as least squares with a constant term always gives. ✅
Mean moving range of the 365 baseline residuals.
Individuals chart. Centre line 0, limits
EWMA chart. Centre line 0, start value
With these settings the EWMA limits are at one standard deviation of the residuals. ✅
Test the limits on the baseline year. No residual of the 365 is beyond ±77.1 kWh. The EWMA is beyond ±25.7 kWh on 2 days (days 238 and 359). This is the “count the false alarms on a quiet period” check, and every chart needs it before it is trusted. With an ARL of 560, about
Before the measure, days 365 to 499. The residual mean is +3.6 kWh: the baseline still predicts the building well. The individuals chart signals on days 441 and 460, both above the upper limit. No cause is known, so they are recorded as unexplained. The EWMA chart gives no signal in these 135 days. ✅
Individuals chart after day 500. The first point beyond a limit is day 505, with a residual of
EWMA chart after day 500. The EWMA passes the lower limit on day 502, with
Run rule. All residuals from day 500 are below zero, so the eighth successive point below the centre line arrives on day 507. ✅
Size of the shift. The residual mean of days 500 to 729 is
Expected shift. A saving of 12 percent on a predicted 525.5 kWh is
A saving of 3 percent. The script rescales the same data to a saving of 3 percent, a shift of about half a standard deviation. The individuals chart first signals on day 625, which is 125 days late. The EWMA chart signals on day 519, after 19 days. These are single cases; the average run lengths of the table, 155 and 44 points, say what to expect on average. ✅
Raw energy on a chart. The script also puts the raw energy of the baseline year on an individuals chart. Its limits are 317 to 834 kWh, and 45 of the 365 days are beyond them with no fault present. ✅
The script generates both data sets, builds the limits for the cold room, adds the disturbed day, then fits the energy baseline and runs both charts on its residuals. It saves one plot with the three charts.
"""Individuals and EWMA control charts: cold room daily means, building energy residuals."""import numpy as npimport matplotlib.pyplot as plt
def cold_room_minutes(seed=11, days=14): rng = np.random.default_rng(seed) n = days * 1440 t = np.empty(n); temp = 4.0; on = False; out = [] for i in range(n): minute = i % 1440 # door openings are more likely in working hours door = (480 <= minute < 1020) and (rng.random() < 0.035) if temp >= 5.0: on = True if temp <= 3.0: on = False temp += (-0.30 if on else 0.10) + (0.35 if door else 0.0) t[i] = temp + rng.normal(0.0, 0.05) # sensor noise, 0.05 °C return t
def building_daily(seed=23, days=730): rng = np.random.default_rng(seed) d = np.arange(days) temp = 21.0 + 4.5 * np.sin(2 * np.pi * (d - 20) / 365.0) + rng.normal(0, 1.6, days) weekday = (d % 7) < 5 # day 0 is a Monday cdd = np.clip(temp - 18.0, 0.0, None) # cooling degree days, base 18 °C energy = 310.0 + 42.0 * cdd + np.where(weekday, 180.0, 0.0) + rng.normal(0, 28.0, days) # an energy-saving measure is installed on day 500: 12 percent less from then on energy[500:] *= 0.88 return d, temp, weekday, energy # kWh a day
D2 = 1.128 # mean range of two normal readings, in units of sigmaLAM, L = 0.2, 3.0 # EWMA weight and limit width
def individuals_limits(x): """Centre line, mean moving range, lower and upper limit of an individuals chart.""" centre = x.mean() mr_bar = np.abs(np.diff(x)).mean() half = 3.0 / D2 * mr_bar # 3/1.128 = 2.66 return centre, mr_bar, centre - half, centre + half
def ewma(x, start, lam=LAM): z = np.empty(x.size) prev = start for i, v in enumerate(x): prev = lam * v + (1.0 - lam) * prev z[i] = prev return z
def first_run(x, centre, length=8): """Index at which `length` successive points on one side of the centre is completed.""" side = np.sign(x - centre) run = 0 for i in range(x.size): run = run + 1 if (i > 0 and side[i] == side[i - 1]) else 1 if run >= length: return i return None
# ---------- Application 1: daily mean temperature of the cold room ----------minutes = cold_room_minutes()daily = minutes.reshape(14, 1440).mean(axis=1)centre, mr_bar, lcl, ucl = individuals_limits(daily)sigma_mr = mr_bar / D2print("Application 1: cold room, 14 daily means (degC)")print(" " + " ".join(f"{v:.3f}" for v in daily[:7]))print(" " + " ".join(f"{v:.3f}" for v in daily[7:]))print(f" centre {centre:.4f}, mean moving range {mr_bar:.5f}, sigma {sigma_mr:.5f}")print(f" limits {lcl:.4f} to {ucl:.4f}")print(f" days beyond the limits: {np.where((daily > ucl) | (daily < lcl))[0].tolist()}")dev = daily - centrer1 = (dev[1:] * dev[:-1]).sum() / (dev ** 2).sum()print(f" sample standard deviation s {daily.std(ddof=1):.5f}, lag-1 autocorrelation {r1:.2f}")
WARM, COOL = 0.10, 0.30 # degC per minute, compressor off and onHOLD = 60.0 # minutes the compressor is held off on day 10rise = WARM * HOLDrecover = rise / COOLadded = 0.5 * rise * (HOLD + recover) / 1440.0disturbed = daily.copy()disturbed[10] += addedprint(f" hold {HOLD:.0f} min: rise {rise:.1f} degC, recovery {recover:.0f} min, " f"added to the day's mean {added:.4f} degC")print(f" day 10: {daily[10]:.4f} becomes {disturbed[10]:.4f}, " f"{(disturbed[10] - centre) / sigma_mr:.1f} sigma above the centre line")hold_min = np.sqrt((ucl - daily[10]) * 2.0 * 1440.0 / (WARM * (1.0 + WARM / COOL)))print(f" shortest hold that puts day 10 above the upper limit: {hold_min:.1f} min")c2, m2, l2, u2 = individuals_limits(disturbed)print(f" limits if day 10 is wrongly included: {l2:.4f} to {u2:.4f} " f"(mean moving range {m2:.5f})")
# the same chart on readings that are not independentfor name, x in (("minute readings", minutes), ("hourly means", minutes.reshape(-1, 60).mean(axis=1))): c, m, lo, hi = individuals_limits(x) out = int(((x > hi) | (x < lo)).sum()) print(f" {name}: {out} of {x.size} beyond the limits ({100.0 * out / x.size:.1f} %)")
# ---------- Application 2: residuals of the energy baseline ----------d, temp, weekday, energy = building_daily()cdd = np.clip(temp - 18.0, 0.0, None)X = np.column_stack([np.ones(d.size), cdd, weekday.astype(float)])b, *_ = np.linalg.lstsq(X[:365], energy[:365], rcond=None)predicted = X @ bresid = energy - predictedrmse = np.sqrt((resid[:365] ** 2).sum() / (365 - 3))print("Application 2: building energy, baseline from days 0 to 364")print(f" model: {b[0]:.1f} + {b[1]:.2f} CDD + {b[2]:.1f} weekday, RMSE {rmse:.1f} kWh")
_, mr_res, _, _ = individuals_limits(resid[:365])sigma = mr_res / D2lim_i = 3.0 * sigmalim_e = L * sigma * np.sqrt(LAM / (2.0 - LAM))print(f" first-year residuals: mean {abs(resid[:365].mean()):.2f}, mean moving range " f"{mr_res:.2f}, sigma {sigma:.2f} kWh")print(f" individuals limits +/-{lim_i:.1f} kWh, EWMA limits +/-{lim_e:.1f} kWh")z1 = ewma(resid[:365], 0.0)print(f" first year beyond the limits: individuals " f"{int((np.abs(resid[:365]) > lim_i).sum())}, EWMA {int((np.abs(z1) > lim_e).sum())} " f"(days {np.where(np.abs(z1) > lim_e)[0].tolist()})")
day2 = d[365:]r2 = resid[365:]z2 = ewma(r2, 0.0)sig_i = day2[np.abs(r2) > lim_i]sig_e = day2[np.abs(z2) > lim_e]print(f" days 365 to 499: individuals signals on days {sig_i[sig_i < 500].tolist()}, " f"EWMA signals on days {sig_e[sig_e < 500].tolist()}")fi, fe = sig_i[sig_i >= 500][0], sig_e[sig_e >= 500][0]print(f" first signal after day 500: individuals day {fi} (residual {resid[fi]:.1f}), " f"EWMA day {fe} (z {z2[fe - 365]:.1f})")post = resid[500:]print(f" eight successive residuals below zero completed on day " f"{500 + first_run(post, 0.0)}")print(f" residual mean: days 365 to 499 {resid[365:500].mean():+.1f}, " f"days 500 to 729 {post.mean():+.1f} kWh")print(f" mean predicted energy, days 500 to 729: {predicted[500:].mean():.1f} kWh, " f"shift is {100.0 * post.mean() / predicted[500:].mean():.1f} %")print(f" 12 % of the predicted energy: {0.12 * predicted[500:].mean():.1f} kWh")
# a smaller saving of 3 percent, made from the same datasmall = energy.copy()small[500:] = small[500:] / 0.88 * 0.97rs = (small - predicted)[365:]zs = ewma(rs, 0.0)si = day2[(np.abs(rs) > lim_i) & (day2 >= 500)]se = day2[(np.abs(zs) > lim_e) & (day2 >= 500)]print(f" with a 3 % saving: individuals day {si[0]}, EWMA day {se[0]}")
# raw energy on an individuals chart, for comparisonc, m, lo, hi = individuals_limits(energy[:365])out = int(((energy[:365] > hi) | (energy[:365] < lo)).sum())print(f" raw energy, first year: limits {lo:.0f} to {hi:.0f} kWh, " f"{out} of 365 days beyond them")
# ---------- Plot ----------fig, ax = plt.subplots(3, 1, figsize=(8, 10))ax[0].plot(np.arange(14), disturbed, "o-")for v in (lcl, centre, ucl): ax[0].axhline(v, color="gray", linewidth=0.8, linestyle="--")ax[0].set_xlabel("day")ax[0].set_ylabel("daily mean (degC)")ax[0].set_title("Cold room: individuals chart with the disturbed day 10")ax[1].plot(day2, r2, ".", markersize=4)for v in (-lim_i, 0.0, lim_i): ax[1].axhline(v, color="gray", linewidth=0.8, linestyle="--")ax[1].axvline(500, color="black", linewidth=0.8)ax[1].set_ylabel("residual (kWh)")ax[1].set_title("Energy residuals: individuals chart")ax[2].plot(day2, z2)for v in (-lim_e, 0.0, lim_e): ax[2].axhline(v, color="gray", linewidth=0.8, linestyle="--")ax[2].axvline(500, color="black", linewidth=0.8)ax[2].set_xlabel("day")ax[2].set_ylabel("EWMA of residual (kWh)")ax[2].set_title("Energy residuals: EWMA chart")fig.tight_layout()fig.savefig("control_charts.png", dpi=120)print("Saved control_charts.png")Expected output
Application 1: cold room, 14 daily means (degC) 4.055 4.037 4.015 4.004 3.997 4.000 4.013 3.997 4.006 4.006 4.011 4.007 4.008 4.024 centre 4.0128, mean moving range 0.00968, sigma 0.00858 limits 3.9870 to 4.0385 days beyond the limits: [0] sample standard deviation s 0.01618, lag-1 autocorrelation 0.46 hold 60 min: rise 6.0 degC, recovery 20 min, added to the day's mean 0.1667 degC day 10: 4.0107 becomes 4.1773, 19.2 sigma above the centre line shortest hold that puts day 10 above the upper limit: 24.5 min limits if day 10 is wrongly included: 3.9308 to 4.1186 (mean moving range 0.03532) minute readings: 12262 of 20160 beyond the limits (60.8 %) hourly means: 7 of 336 beyond the limits (2.1 %)Application 2: building energy, baseline from days 0 to 364 model: 306.6 + 41.61 CDD + 182.1 weekday, RMSE 27.3 kWh first-year residuals: mean 0.00, mean moving range 29.00, sigma 25.71 kWh individuals limits +/-77.1 kWh, EWMA limits +/-25.7 kWh first year beyond the limits: individuals 0, EWMA 2 (days [238, 359]) days 365 to 499: individuals signals on days [441, 460], EWMA signals on days [] first signal after day 500: individuals day 505 (residual -81.6), EWMA day 502 (z -27.0) eight successive residuals below zero completed on day 507 residual mean: days 365 to 499 +3.6, days 500 to 729 -60.2 kWh mean predicted energy, days 500 to 729: 525.5 kWh, shift is -11.5 % 12 % of the predicted energy: 63.1 kWh with a 3 % saving: individuals day 625, EWMA day 519 raw energy, first year: limits 317 to 834 kWh, 45 of 365 days beyond themSaved control_charts.png1. A pump’s discharge pressure is read once a day for ten days, in bar: 6.2, 6.4, 6.1, 6.3, 6.5, 6.2, 6.0, 6.3, 6.4, 6.1. Find the centre line and the limits of an individuals chart.
2. A stable process with independent readings is charted once an hour with 3-sigma limits and no run rules. How many false alarms are expected in a year of 8760 hours, and what is the mean time between them in days?
3. The residuals of a baseline have
(a)
4. In the cold room of Application 1 (limits 3.9870 to 4.0385 °C), the compressor is held off for 40 minutes on day 8, whose undisturbed mean is 4.006 °C. Find the new daily mean and say whether the chart signals.
Rise
5. A baseline predicts a mean of 480 kWh a day, and its residuals are independent and normal with
The shift is
A saving measure lowers the daily energy of a building by half of one standard deviation of its ordinary day to day movement. Which chart shows the change first?
The 120 daily values are an illustration made by a seeded generator: independent values with a standard deviation of 25 kWh, such as the residuals of a baseline. They are not the lesson's data. From the start day the mean falls by the size you set, as a saving measure would make it fall. The thin stepped line is that true mean. Both charts take their centre line and their estimate of σ from days 0 to 19 only, by the moving range method, so the limits never see the shift. The EWMA uses the lesson's λ = 0.2 and L = 3 and starts at the centre line. A ring marks the first point beyond a limit after the shift. Points beyond a limit before the shift are false alarms. With only 20 days, the estimate of σ is itself uncertain: press New data and watch it change.
Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.
1. The residuals of a baseline have a mean of zero and a mean moving range of 4.5 kWh. What are the limits of an EWMA chart with λ = 0.2 and L = 3?
2. The mean of a process shifts by one standard deviation and stays there. The readings are independent and normal. How long does an individuals chart with 3-sigma limits wait, on average, for its first point beyond a limit?
3. A stable process with independent normal readings is charted for 120 days on an individuals chart with 3-sigma limits. Nothing changes. What is the chance of at least one point beyond the limits?
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.