Catching small shifts
Use CUSUM and EWMA charts, which build up evidence over time, to catch shifts too small for a single point to reveal.
What runs in CodeSplash
- Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA) Verified in Python and R
- Monotonic trend tests (Mann–Kendall family) Verified in Python and R
- Change-point tests (level shifts) Verified in Python and R
You will be able to
- Explain why a Shewhart chart is slow to catch a small shift
- Read a CUSUM against a target
- Say how the EWMA weight trades sensitivity against reaction speed
Read first
A chart with no memory
ReadA standard chart judges each point by itself, so a shift of one sigma can go unnoticed for many points. Each point looks ordinary, even though together they don't.
Two charts add memory:
- CUSUMCUSUM testTracks the running sum of (recursive or OLS) residuals; a stable regression keeps it inside the boundary lines. adds up departures from a target.
- EWMAEWMA chartA control chart of a running weighted average, good at catching small sustained shifts. plots a running average that weights recent points most.
A river changes
PredictPredict first
Annual flow of the Nile has 100 years of data, with sigma 118 and a center line of 919. The river's level dropped partway through. What kind of signal do you expect on an individuals chart with Nelson's rules?
Reveal
21 points signal, nearly all from run rules rather than from points beyond three sigma. The drop is about one sigma, too small for any single year to stand out. A shift like this is why run rules exist.
I–MR chart of Flow: 100 points; 21 signals (Nelson rules).
- Center
- 919.35
- σ
- 118.13
- Subgroups
- 100
- Signals
- 21
Plots
View data
| Center | Chart | Subgroup | LCL | Rules | UCL | Flow | Signal |
|---|---|---|---|---|---|---|---|
| 919.35 | Individuals | 1 | 564.95 | 1273.75 | 1,120 | false | |
| 919.35 | Individuals | 2 | 564.95 | 1273.75 | 1,160 | false | |
| 919.35 | Individuals | 3 | 564.95 | 1273.75 | 963 | false | |
| 919.35 | Individuals | 4 | 564.95 | 5 | 1273.75 | 1,210 | true |
| 919.35 | Individuals | 5 | 564.95 | 5,6 | 1273.75 | 1,160 | true |
| 919.35 | Individuals | 6 | 564.95 | 5,6 | 1273.75 | 1,160 | true |
| 919.35 | Individuals | 7 | 564.95 | 1273.75 | 813 | false | |
| 919.35 | Individuals | 8 | 564.95 | 5,6 | 1273.75 | 1,230 | true |
| 919.35 | Individuals | 9 | 564.95 | 1,5,6 | 1273.75 | 1,370 | true |
| 919.35 | Individuals | 10 | 564.95 | 6 | 1273.75 | 1,140 | true |
| 919.35 | Individuals | 11 | 564.95 | 1273.75 | 995 | false | |
| 919.35 | Individuals | 12 | 564.95 | 1273.75 | 935 | false | |
| 919.35 | Individuals | 13 | 564.95 | 1273.75 | 1,110 | false | |
| 919.35 | Individuals | 14 | 564.95 | 1273.75 | 994 | false | |
| 919.35 | Individuals | 15 | 564.95 | 1273.75 | 1,020 | false | |
| 919.35 | Individuals | 16 | 564.95 | 2 | 1273.75 | 960 | true |
| 919.35 | Individuals | 17 | 564.95 | 2 | 1273.75 | 1,180 | true |
| 919.35 | Individuals | 18 | 564.95 | 1273.75 | 799 | false | |
| 919.35 | Individuals | 19 | 564.95 | 1273.75 | 958 | false | |
| 919.35 | Individuals | 20 | 564.95 | 1273.75 | 1,140 | false | |
| 919.35 | Individuals | 21 | 564.95 | 1273.75 | 1,100 | false | |
| 919.35 | Individuals | 22 | 564.95 | 1273.75 | 1,210 | false | |
| 919.35 | Individuals | 23 | 564.95 | 6 | 1273.75 | 1,150 | true |
| 919.35 | Individuals | 24 | 564.95 | 5,6 | 1273.75 | 1,250 | true |
| 919.35 | Individuals | 25 | 564.95 | 5,6 | 1273.75 | 1,260 | true |
| 919.35 | Individuals | 26 | 564.95 | 5,6 | 1273.75 | 1,220 | true |
| 919.35 | Individuals | 27 | 564.95 | 2 | 1273.75 | 1,030 | true |
| 919.35 | Individuals | 28 | 564.95 | 2,6 | 1273.75 | 1,100 | true |
| 919.35 | Individuals | 29 | 564.95 | 1273.75 | 774 | false | |
| 919.35 | Individuals | 30 | 564.95 | 1273.75 | 840 | false | |
| 919.35 | Individuals | 31 | 564.95 | 1273.75 | 874 | false | |
| 919.35 | Individuals | 32 | 564.95 | 1273.75 | 694 | false | |
| 919.35 | Individuals | 33 | 564.95 | 1273.75 | 940 | false | |
| 919.35 | Individuals | 34 | 564.95 | 1273.75 | 833 | false | |
| 919.35 | Individuals | 35 | 564.95 | 1273.75 | 701 | false | |
| 919.35 | Individuals | 36 | 564.95 | 1273.75 | 916 | false | |
| 919.35 | Individuals | 37 | 564.95 | 1273.75 | 692 | false | |
| 919.35 | Individuals | 38 | 564.95 | 1273.75 | 1,020 | false | |
| 919.35 | Individuals | 39 | 564.95 | 1273.75 | 1,050 | false | |
| 919.35 | Individuals | 40 | 564.95 | 1273.75 | 969 | false | |
| 919.35 | Individuals | 41 | 564.95 | 1273.75 | 831 | false | |
| 919.35 | Individuals | 42 | 564.95 | 1273.75 | 726 | false | |
| 919.35 | Individuals | 43 | 564.95 | 1 | 1273.75 | 456 | true |
| 919.35 | Individuals | 44 | 564.95 | 1273.75 | 824 | false | |
| 919.35 | Individuals | 45 | 564.95 | 1273.75 | 702 | false | |
| 919.35 | Individuals | 46 | 564.95 | 1273.75 | 1,120 | false | |
| 919.35 | Individuals | 47 | 564.95 | 1273.75 | 1,100 | false | |
| 919.35 | Individuals | 48 | 564.95 | 1273.75 | 832 | false | |
| 919.35 | Individuals | 49 | 564.95 | 1273.75 | 764 | false | |
| 919.35 | Individuals | 50 | 564.95 | 1273.75 | 821 | false | |
| 919.35 | Individuals | 51 | 564.95 | 1273.75 | 768 | false | |
| 919.35 | Individuals | 52 | 564.95 | 1273.75 | 845 | false | |
| 919.35 | Individuals | 53 | 564.95 | 1273.75 | 864 | false | |
| 919.35 | Individuals | 54 | 564.95 | 1273.75 | 862 | false | |
| 919.35 | Individuals | 55 | 564.95 | 1273.75 | 698 | false | |
| 919.35 | Individuals | 56 | 564.95 | 2 | 1273.75 | 845 | true |
| 919.35 | Individuals | 57 | 564.95 | 2 | 1273.75 | 744 | true |
| 919.35 | Individuals | 58 | 564.95 | 2 | 1273.75 | 796 | true |
| 919.35 | Individuals | 59 | 564.95 | 1273.75 | 1,040 | false | |
| 919.35 | Individuals | 60 | 564.95 | 1273.75 | 759 | false |
First 60 of 200 rows.
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 1 | 1,120 | 919.35 | 564.95 | 1273.75 | |
| 2 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | |
| 3 | 1 | 963 | 919.35 | 564.95 | 1273.75 | |
| 4 | 1 | 1,210 | 919.35 | 564.95 | 1273.75 | 5 |
| 5 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 6 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 7 | 1 | 813 | 919.35 | 564.95 | 1273.75 | |
| 8 | 1 | 1,230 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 9 | 1 | 1,370 | 919.35 | 564.95 | 1273.75 | 1, 5, 6 |
| 10 | 1 | 1,140 | 919.35 | 564.95 | 1273.75 | 6 |
| 11 | 1 | 995 | 919.35 | 564.95 | 1273.75 | |
| 12 | 1 | 935 | 919.35 | 564.95 | 1273.75 | |
| 13 | 1 | 1,110 | 919.35 | 564.95 | 1273.75 | |
| 14 | 1 | 994 | 919.35 | 564.95 | 1273.75 | |
| 15 | 1 | 1,020 | 919.35 | 564.95 | 1273.75 | |
| 16 | 1 | 960 | 919.35 | 564.95 | 1273.75 | 2 |
| 17 | 1 | 1,180 | 919.35 | 564.95 | 1273.75 | 2 |
| 18 | 1 | 799 | 919.35 | 564.95 | 1273.75 | |
| 19 | 1 | 958 | 919.35 | 564.95 | 1273.75 | |
| 20 | 1 | 1,140 | 919.35 | 564.95 | 1273.75 | |
| 21 | 1 | 1,100 | 919.35 | 564.95 | 1273.75 | |
| 22 | 1 | 1,210 | 919.35 | 564.95 | 1273.75 | |
| 23 | 1 | 1,150 | 919.35 | 564.95 | 1273.75 | 6 |
| 24 | 1 | 1,250 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 25 | 1 | 1,260 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 26 | 1 | 1,220 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 27 | 1 | 1,030 | 919.35 | 564.95 | 1273.75 | 2 |
| 28 | 1 | 1,100 | 919.35 | 564.95 | 1273.75 | 2, 6 |
| 29 | 1 | 774 | 919.35 | 564.95 | 1273.75 | |
| 30 | 1 | 840 | 919.35 | 564.95 | 1273.75 | |
| 31 | 1 | 874 | 919.35 | 564.95 | 1273.75 | |
| 32 | 1 | 694 | 919.35 | 564.95 | 1273.75 | |
| 33 | 1 | 940 | 919.35 | 564.95 | 1273.75 | |
| 34 | 1 | 833 | 919.35 | 564.95 | 1273.75 | |
| 35 | 1 | 701 | 919.35 | 564.95 | 1273.75 | |
| 36 | 1 | 916 | 919.35 | 564.95 | 1273.75 | |
| 37 | 1 | 692 | 919.35 | 564.95 | 1273.75 | |
| 38 | 1 | 1,020 | 919.35 | 564.95 | 1273.75 | |
| 39 | 1 | 1,050 | 919.35 | 564.95 | 1273.75 | |
| 40 | 1 | 969 | 919.35 | 564.95 | 1273.75 |
First 40 of 100 rows.
- σ estimated from all subgroups.
- σ = mean moving range / 1.128.
The exact R script · R R version 4.5.1 (2025-06-13)
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec b424e3534625c659
# Dataset: q1_nile (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_spc_*(): twin of codesplash.quality.spc (qcc 2.7 conventions)
# Classic equivalent: qcc::qcc(qcc.groups(x, sample), type = "xbar"), qcc(type = "R" | "S" | "xbar.one" |
# "p" | "np" | "c" | "u"), qcc::cusum(), qcc::ewma() — same constants and sigma estimators.
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/q1_nile.parquet", col_select = c("Flow")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("Flow")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("Flow")) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart <- "imr"
value_col <- "Flow"
subgroup_col <- NULL
size_col <- NULL
phase1 <- as.integer(0)
nsigmas <- 3
rules <- "nelson"
x <- as.numeric(df[[value_col]])
labels_raw <- if (!is.null(subgroup_col)) as.character(df[[subgroup_col]]) else NULL
attribute <- chart %in% c("p", "np", "c", "u", "laney_p")
if (attribute) {
sizes <- if (!is.null(size_col)) as.numeric(df[[size_col]]) else NULL
if (!is.null(labels_raw)) {
lv <- unique(labels_raw)
d <- vapply(lv, function(l) sum(x[labels_raw == l]), 0)
n_ <- if (!is.null(sizes)) vapply(lv, function(l) sum(sizes[labels_raw == l]), 0) else NULL
labels <- lv
} else {
d <- x; n_ <- sizes; labels <- as.character(seq_along(x))
}
res <- cs_spc_attributes(unname(d), if (is.null(n_)) NULL else unname(n_), chart, phase1, nsigmas)
} else {
sg <- cs_spc_subgroups(x, labels_raw, NULL)
groups <- sg$groups; labels <- sg$labels
if (length(groups) < 2) { # control limits need two subgroups (registry/errors.yaml)
if (!is.null(subgroup_col)) cs_error("CS_E_TOO_FEW_GROUPS", column = subgroup_col, min = 2, k = length(groups))
cs_check_rows(length(x), 2, "A control chart")
}
if (chart == "cusum") {
res <- cs_spc_cusum(groups, phase1, NULL, 5, 1)
} else if (chart == "ewma") {
res <- cs_spc_ewma(groups, phase1, NULL, 0.2, nsigmas)
} else {
if (chart == "imr" && any(lengths(groups) != 1)) stop("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.", call. = FALSE)
res <- cs_spc_variables(groups, chart, phase1, nsigmas)
}
}
m <- length(labels)
# %% Signals
if (chart == "cusum") {
stat <- res$stat
center <- rep(res$center, m)
viol_rules <- lapply(seq_len(m), function(i) if (res$pos[i] > res$h || res$neg[i] < -res$h) 1L else integer())
lcl <- rep(-res$h, m); ucl <- rep(res$h, m)
} else if (chart == "ewma") {
stat <- res$ewma
center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- lapply(seq_len(m), function(i) if (stat[i] > ucl[i] || stat[i] < lcl[i]) 1L else integer())
} else {
stat <- res$stat; center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- cs_spc_rules(stat, center, lcl, ucl, res$sd, rules)
}
violations <- which(lengths(viol_rules) > 0)
sec <- res$secondary
sec_viol <- integer()
if (!is.null(sec)) sec_viol <- which(is.finite(sec$stat) & (sec$stat > sec$ucl | sec$stat < sec$lcl))
# %% Tables and chart
chart_labels <- c(xbar_r = "X̄–R", xbar_s = "X̄–S", imr = "I–MR", p = "p", np = "np", c = "c", u = "u",
laney_p = "Laney p′", cusum = "CUSUM", ewma = "EWMA")
label <- chart_labels[[chart]]
panel <- c(xbar_r = "X̄", xbar_s = "X̄", imr = "Individuals", p = "p", np = "np", c = "c", u = "u", laney_p = "p′",
cusum = "CUSUM", ewma = "EWMA")[[chart]]
rule_text <- vapply(viol_rules, function(r) paste(r, collapse = ","), "")
idx <- seq_len(m)
if (chart == "cusum") {
ch <- data.frame(index = c(idx, idx), value = c(res$pos, res$neg), center = 0, lcl = c(lcl, lcl), ucl = c(ucl, ucl),
violation = c(lengths(viol_rules) > 0, lengths(viol_rules) > 0), rule = c(rule_text, rule_text),
chart = rep(c("C⁺", "C⁻"), each = m), stringsAsFactors = FALSE)
} else {
ch <- data.frame(index = idx, value = stat, center = center, lcl = lcl, ucl = ucl, violation = lengths(viol_rules) > 0,
rule = rule_text, chart = panel, stringsAsFactors = FALSE)
if (!is.null(sec)) ch <- rbind(ch, data.frame(index = idx, value = sec$stat, center = sec$center, lcl = sec$lcl, ucl = sec$ucl,
violation = idx %in% sec_viol, rule = ifelse(idx %in% sec_viol, "1", ""),
chart = sec$label, stringsAsFactors = FALSE))
}
charts <- list(cs_chart(
"control", "control-chart", sprintf("%s chart of %s", label, value_col),
list(index = cs_col(if (!attribute || !is.null(labels_raw)) "Subgroup" else "Sample", ch$index),
value = cs_col(if (chart == "imr") value_col else "Statistic", ch$value),
center = cs_col("Center", ch$center), lcl = cs_col("LCL", ch$lcl), ucl = cs_col("UCL", ch$ucl),
violation = cs_col("Signal", ch$violation, "boolean"), rule = cs_col("Rules", ch$rule, "categorical"),
chart = cs_col("Chart", ch$chart, "categorical"))))
tables <- list(list(
key = "points", title = "Points and limits",
columns = list(list(key = "label", label = "Subgroup", type = "string"), list(key = "n", label = "n", type = "number"),
list(key = "stat", label = "Statistic", type = "number"), list(key = "center", label = "Center", type = "number"),
list(key = "lcl", label = "LCL", type = "number"), list(key = "ucl", label = "UCL", type = "number"),
list(key = "rules", label = "Rules broken", type = "string")),
rows = data.frame(label = labels, n = as.numeric(res$sizes), stat = stat, center = center, lcl = lcl, ucl = ucl,
rules = vapply(viol_rules, function(r) paste(r, collapse = ", "), ""), stringsAsFactors = FALSE)
))
# %% Result
sizes_arr <- as.numeric(res$sizes)
values <- list(
chart = chart, chart_label = label, n_subgroups = m, mean_size = mean(sizes_arr),
center = center[1], sigma = res$sigma,
stat = I(stat), lcl = I(lcl), ucl = I(ucl),
violations = I(violations), violation_rules = I(rule_text[lengths(viol_rules) > 0]), n_signals = length(violations),
sec_stat = if (!is.null(sec)) I(sec$stat) else NULL, sec_center = if (!is.null(sec)) sec$center[1] else NULL,
sec_lcl = if (!is.null(sec)) I(sec$lcl) else NULL, sec_ucl = if (!is.null(sec)) I(sec$ucl) else NULL,
sec_violations = I(sec_viol),
cusum_pos = if (chart == "cusum") I(res$pos) else NULL,
cusum_neg = if (chart == "cusum") I(res$neg) else NULL
)
rule_names <- c(basic = "points beyond the limits", western_electric = "Western Electric rules", nelson = "Nelson rules")
summary <- sprintf("%s chart of %s: %d %s; ", label, value_col, m, if (mean(sizes_arr) != 1) "subgroups" else "points")
summary <- paste0(summary, if (length(violations)) sprintf("%d signal%s (%s).", length(violations), if (length(violations) != 1) "s" else "",
if (chart %in% c("cusum", "ewma")) "beyond the limits" else rule_names[[rules]]) else "no signals.")
notes <- sprintf("σ estimated from %s.", if (phase1 > 0 && phase1 < m) sprintf("the first %d subgroups (phase I)", phase1) else "all subgroups")
if (chart %in% c("xbar_r", "xbar_s", "imr"))
notes <- c(notes, c(xbar_r = "σ = mean(R / d2) (qcc UWAVE-R).", xbar_s = "σ = mean(S / c4) (qcc UWAVE-SD).", imr = "σ = mean moving range / 1.128.")[[chart]])
cs_publish(list(
method = "spc.control_chart",
methodVersion = "1.0.1",
title = sprintf("%s control chart", label),
engine = cs_engine_info("codesplashr", "nanoparquet"),
n = length(x),
summary = summary,
statistics = list(list(key = "center", label = "Center", value = center[1]), list(key = "sigma", label = "σ", value = res$sigma),
list(key = "n_subgroups", label = "Subgroups", value = m, format = "integer"),
list(key = "n_signals", label = "Signals", value = length(violations), format = "integer")),
tables = tables,
charts = charts,
warnings = warnings,
notes = as.list(notes),
values = values
))
I–MR chart of Flow: 100 points; 21 signals (Nelson rules).
- Center
- 919.35
- σ
- 118.13
- Subgroups
- 100
- Signals
- 21
To keep this page light, the plots are shown once, under the R tab.
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 1 | 1,120 | 919.35 | 564.95 | 1273.75 | |
| 2 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | |
| 3 | 1 | 963 | 919.35 | 564.95 | 1273.75 | |
| 4 | 1 | 1,210 | 919.35 | 564.95 | 1273.75 | 5 |
| 5 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 6 | 1 | 1,160 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 7 | 1 | 813 | 919.35 | 564.95 | 1273.75 | |
| 8 | 1 | 1,230 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 9 | 1 | 1,370 | 919.35 | 564.95 | 1273.75 | 1, 5, 6 |
| 10 | 1 | 1,140 | 919.35 | 564.95 | 1273.75 | 6 |
| 11 | 1 | 995 | 919.35 | 564.95 | 1273.75 | |
| 12 | 1 | 935 | 919.35 | 564.95 | 1273.75 | |
| 13 | 1 | 1,110 | 919.35 | 564.95 | 1273.75 | |
| 14 | 1 | 994 | 919.35 | 564.95 | 1273.75 | |
| 15 | 1 | 1,020 | 919.35 | 564.95 | 1273.75 | |
| 16 | 1 | 960 | 919.35 | 564.95 | 1273.75 | 2 |
| 17 | 1 | 1,180 | 919.35 | 564.95 | 1273.75 | 2 |
| 18 | 1 | 799 | 919.35 | 564.95 | 1273.75 | |
| 19 | 1 | 958 | 919.35 | 564.95 | 1273.75 | |
| 20 | 1 | 1,140 | 919.35 | 564.95 | 1273.75 | |
| 21 | 1 | 1,100 | 919.35 | 564.95 | 1273.75 | |
| 22 | 1 | 1,210 | 919.35 | 564.95 | 1273.75 | |
| 23 | 1 | 1,150 | 919.35 | 564.95 | 1273.75 | 6 |
| 24 | 1 | 1,250 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 25 | 1 | 1,260 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 26 | 1 | 1,220 | 919.35 | 564.95 | 1273.75 | 5, 6 |
| 27 | 1 | 1,030 | 919.35 | 564.95 | 1273.75 | 2 |
| 28 | 1 | 1,100 | 919.35 | 564.95 | 1273.75 | 2, 6 |
| 29 | 1 | 774 | 919.35 | 564.95 | 1273.75 | |
| 30 | 1 | 840 | 919.35 | 564.95 | 1273.75 | |
| 31 | 1 | 874 | 919.35 | 564.95 | 1273.75 | |
| 32 | 1 | 694 | 919.35 | 564.95 | 1273.75 | |
| 33 | 1 | 940 | 919.35 | 564.95 | 1273.75 | |
| 34 | 1 | 833 | 919.35 | 564.95 | 1273.75 | |
| 35 | 1 | 701 | 919.35 | 564.95 | 1273.75 | |
| 36 | 1 | 916 | 919.35 | 564.95 | 1273.75 | |
| 37 | 1 | 692 | 919.35 | 564.95 | 1273.75 | |
| 38 | 1 | 1,020 | 919.35 | 564.95 | 1273.75 | |
| 39 | 1 | 1,050 | 919.35 | 564.95 | 1273.75 | |
| 40 | 1 | 969 | 919.35 | 564.95 | 1273.75 |
First 40 of 100 rows.
- σ estimated from all subgroups.
- σ = mean moving range / 1.128.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec b424e3534625c659
# Dataset: q1_nile (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.quality import spc # twin of codesplashr::cs_spc_* (qcc 2.7 conventions)
# Classic equivalent in R: qcc::qcc(data, type = "xbar" | "R" | "S" | "xbar.one" | "p" | "np" | "c" | "u"),
# qcc::cusum(), qcc::ewma(). Python has no maintained SPC library with the same constants.
# %% Data
df = pd.read_parquet("tests/parity/fixtures/q1_nile.parquet", columns=["Flow"])
n_input = len(df)
df = df.dropna(subset=["Flow"]) # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["Flow"]) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart = "imr"
value_col = "Flow"
subgroup_col = None
size_col = None
phase1 = int(0)
nsigmas = 3
rules = "nelson"
x = df[value_col].to_numpy(dtype=float)
def _label(v):
return str(int(v)) if isinstance(v, float) and v.is_integer() else str(v)
labels_raw = [_label(v) for v in df[subgroup_col]] if subgroup_col else None
attribute = chart in ("p", "np", "c", "u", "laney_p")
if attribute:
sizes = df[size_col].to_numpy(dtype=float) if size_col else None
if labels_raw is not None:
order = list(dict.fromkeys(labels_raw))
d = np.asarray([x[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order])
n_ = np.asarray([sizes[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order]) if sizes is not None else None
labels = order
else:
d, n_, labels = x, sizes, [str(i + 1) for i in range(len(x))]
res = spc.attributes_chart(d, n_, chart, phase1, nsigmas)
else:
groups, labels = spc.subgroups(x, labels_raw, None)
if len(groups) < 2: # control limits need two subgroups (registry/errors.yaml)
if subgroup_col:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=subgroup_col, min=2, k=len(groups))
cs.check_rows(len(x), 2, "A control chart")
if chart == "cusum":
res = spc.cusum(groups, phase1, None, 5, 1)
elif chart == "ewma":
res = spc.ewma(groups, phase1, None, 0.2, nsigmas)
else:
if chart == "imr" and any(len(g) != 1 for g in groups):
raise ValueError("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.")
res = spc.variables_chart(groups, chart, phase1, nsigmas)
m = len(labels)
# %% Signals
if chart == "cusum":
stat = res["stat"]
center = np.full(m, res["center"])
viol_rules = [[1] if (res["pos"][i] > res["h"] or res["neg"][i] < -res["h"]) else [] for i in range(m)]
lcl = np.full(m, -res["h"])
ucl = np.full(m, res["h"])
elif chart == "ewma":
stat = res["ewma"]
center, lcl, ucl = res["center"], res["lcl"], res["ucl"]
viol_rules = [[1] if (stat[i] > ucl[i] or stat[i] < lcl[i]) else [] for i in range(m)]
else:
stat, center, lcl, ucl = res["stat"], res["center"], res["lcl"], res["ucl"]
viol_rules = spc.run_rules(stat, center, lcl, ucl, res["sd"], rules)
violations = [i + 1 for i in range(m) if viol_rules[i]]
sec = res.get("secondary")
sec_viol = []
if sec:
s_ok = np.isfinite(sec["stat"])
sec_viol = [i + 1 for i in range(m) if s_ok[i] and (sec["stat"][i] > sec["ucl"][i] or sec["stat"][i] < sec["lcl"][i])]
# %% Tables and chart
label = spc.CHART_LABEL[chart]
idx = list(range(1, m + 1))
panel = {"xbar_r": "X̄", "xbar_s": "X̄", "imr": "Individuals", "p": "p", "np": "np", "c": "c", "u": "u", "laney_p": "p′", "cusum": "CUSUM", "ewma": "EWMA"}[chart]
rows_idx, rows_val, rows_c, rows_l, rows_u, rows_v, rows_r, rows_f = [], [], [], [], [], [], [], []
if chart == "cusum":
for name, series in (("C⁺", res["pos"]), ("C⁻", res["neg"])):
rows_idx += idx; rows_val += list(map(float, series)); rows_c += [0.0] * m; rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [name] * m
else:
rows_idx += idx; rows_val += list(map(float, stat)); rows_c += list(map(float, center)); rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [panel] * m
if sec:
rows_idx += idx; rows_val += list(map(float, sec["stat"])); rows_c += list(map(float, sec["center"])); rows_l += list(map(float, sec["lcl"]))
rows_u += list(map(float, sec["ucl"])); rows_v += [i + 1 in sec_viol for i in range(m)]; rows_r += ["1" if i + 1 in sec_viol else "" for i in range(m)]
rows_f += [sec["label"]] * m
charts = [cs.chart(
"control", "control-chart", f"{label} chart of {value_col}",
{"index": cs.col("Subgroup" if not attribute or labels_raw else "Sample", rows_idx),
"value": cs.col(value_col if chart in ("imr",) else "Statistic", rows_val),
"center": cs.col("Center", rows_c), "lcl": cs.col("LCL", rows_l), "ucl": cs.col("UCL", rows_u),
"violation": cs.col("Signal", rows_v, "boolean"), "rule": cs.col("Rules", rows_r, "categorical"),
"chart": cs.col("Chart", rows_f, "categorical")},
)]
table_rows = []
for i in range(m):
table_rows.append({"label": labels[i], "n": float(res["sizes"][i]) if res.get("sizes") is not None else None, "stat": float(stat[i]),
"center": float(center[i]), "lcl": float(lcl[i]), "ucl": float(ucl[i]), "rules": ", ".join(map(str, viol_rules[i]))})
tables = [{
"key": "points", "title": "Points and limits",
"columns": [{"key": "label", "label": "Subgroup", "type": "string"}, {"key": "n", "label": "n", "type": "number"},
{"key": "stat", "label": "Statistic", "type": "number"}, {"key": "center", "label": "Center", "type": "number"},
{"key": "lcl", "label": "LCL", "type": "number"}, {"key": "ucl", "label": "UCL", "type": "number"},
{"key": "rules", "label": "Rules broken", "type": "string"}],
"rows": table_rows,
}]
# %% Result
sizes_arr = np.asarray(res["sizes"], dtype=float)
values = {
"chart": chart, "chart_label": label, "n_subgroups": m, "mean_size": float(np.mean(sizes_arr)),
"center": float(center[0]), "sigma": float(res["sigma"]),
"stat": list(map(float, stat)), "lcl": list(map(float, lcl)), "ucl": list(map(float, ucl)),
"violations": violations, "violation_rules": [",".join(map(str, r)) for r in viol_rules if r], "n_signals": len(violations),
"sec_stat": list(map(float, sec["stat"])) if sec else None, "sec_center": float(sec["center"][0]) if sec else None,
"sec_lcl": list(map(float, sec["lcl"])) if sec else None, "sec_ucl": list(map(float, sec["ucl"])) if sec else None,
"sec_violations": sec_viol,
"cusum_pos": list(map(float, res["pos"])) if chart == "cusum" else None,
"cusum_neg": list(map(float, res["neg"])) if chart == "cusum" else None,
}
rule_names = {"basic": "points beyond the limits", "western_electric": "Western Electric rules", "nelson": "Nelson rules"}
summary = f"{label} chart of {value_col}: {m} {'subgroups' if np.mean(sizes_arr) != 1 else 'points'}; "
summary += f"{len(violations)} signal{'s' if len(violations) != 1 else ''} ({rule_names[rules] if chart not in ('cusum', 'ewma') else 'beyond the limits'})." if violations else "no signals."
notes = [f"σ estimated from {'the first ' + str(phase1) + ' subgroups (phase I)' if 0 < phase1 < m else 'all subgroups'}."]
if chart in ("xbar_r", "xbar_s", "imr"):
notes.append({"xbar_r": "σ = mean(R / d2) (qcc UWAVE-R).", "xbar_s": "σ = mean(S / c4) (qcc UWAVE-SD).", "imr": "σ = mean moving range / 1.128."}[chart])
cs.publish({
"title": f"{label} control chart",
"engine": cs.engine_info("numpy", "pandas"),
"n": len(x),
"summary": summary,
"statistics": [
{"key": "center", "label": "Center", "value": float(center[0])},
{"key": "sigma", "label": "σ", "value": float(res["sigma"])},
{"key": "n_subgroups", "label": "Subgroups", "value": m, "format": "integer"},
{"key": "n_signals", "label": "Signals", "value": len(violations), "format": "integer"},
],
"tables": tables,
"charts": charts,
"warnings": warnings,
"notes": notes,
"values": values,
})
Add it up
In the appCUSUM keeps two running totals, one for each direction. Small departures are ignored through an allowance , and larger ones accumulate:
CUSUM chart of Flow: 100 points; 70 signals (beyond the limits).
- Center
- 1,100
- σ
- 118.13
- Subgroups
- 100
- Signals
- 70
Plots
View data
| Center | Chart | Subgroup | LCL | Rules | UCL | Statistic | Signal |
|---|---|---|---|---|---|---|---|
| 0 | C⁺ | 1 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 2 | −5 | 5 | 0.0079 | false | |
| 0 | C⁺ | 3 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 4 | −5 | 5 | 0.4312 | false | |
| 0 | C⁺ | 5 | −5 | 5 | 0.4391 | false | |
| 0 | C⁺ | 6 | −5 | 5 | 0.4470 | false | |
| 0 | C⁺ | 7 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 8 | −5 | 5 | 0.6005 | false | |
| 0 | C⁺ | 9 | −5 | 5 | 2.386 | false | |
| 0 | C⁺ | 10 | −5 | 5 | 2.225 | false | |
| 0 | C⁺ | 11 | −5 | 5 | 0.8358 | false | |
| 0 | C⁺ | 12 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 13 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 14 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 15 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 16 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 17 | −5 | 5 | 0.1772 | false | |
| 0 | C⁺ | 18 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 19 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 20 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 21 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 22 | −5 | 5 | 0.4312 | false | |
| 0 | C⁺ | 23 | −5 | 5 | 0.3544 | false | |
| 0 | C⁺ | 24 | −5 | 5 | 1.124 | false | |
| 0 | C⁺ | 25 | −5 | 5 | 1.979 | false | |
| 0 | C⁺ | 26 | −5 | 5 | 2.494 | false | |
| 0 | C⁺ | 27 | −5 | 5 | 1.402 | false | |
| 0 | C⁺ | 28 | −5 | 5 | 0.9019 | false | |
| 0 | C⁺ | 29 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 30 | −5 | 5 | 0 | false | |
| 0 | C⁺ | 31 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 32 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 33 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 34 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 35 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 36 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 37 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 38 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 39 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 40 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 41 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 42 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 43 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 44 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 45 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 46 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 47 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 48 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 49 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 50 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 51 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 52 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 53 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 54 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 55 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 56 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 57 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 58 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 59 | −5 | 1 | 5 | 0 | true |
| 0 | C⁺ | 60 | −5 | 1 | 5 | 0 | true |
First 60 of 200 rows.
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 1 | 1,120 | 1,100 | −5 | 5 | |
| 2 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 3 | 1 | 963 | 1,100 | −5 | 5 | |
| 4 | 1 | 1,210 | 1,100 | −5 | 5 | |
| 5 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 6 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 7 | 1 | 813 | 1,100 | −5 | 5 | |
| 8 | 1 | 1,230 | 1,100 | −5 | 5 | |
| 9 | 1 | 1,370 | 1,100 | −5 | 5 | |
| 10 | 1 | 1,140 | 1,100 | −5 | 5 | |
| 11 | 1 | 995 | 1,100 | −5 | 5 | |
| 12 | 1 | 935 | 1,100 | −5 | 5 | |
| 13 | 1 | 1,110 | 1,100 | −5 | 5 | |
| 14 | 1 | 994 | 1,100 | −5 | 5 | |
| 15 | 1 | 1,020 | 1,100 | −5 | 5 | |
| 16 | 1 | 960 | 1,100 | −5 | 5 | |
| 17 | 1 | 1,180 | 1,100 | −5 | 5 | |
| 18 | 1 | 799 | 1,100 | −5 | 5 | |
| 19 | 1 | 958 | 1,100 | −5 | 5 | |
| 20 | 1 | 1,140 | 1,100 | −5 | 5 | |
| 21 | 1 | 1,100 | 1,100 | −5 | 5 | |
| 22 | 1 | 1,210 | 1,100 | −5 | 5 | |
| 23 | 1 | 1,150 | 1,100 | −5 | 5 | |
| 24 | 1 | 1,250 | 1,100 | −5 | 5 | |
| 25 | 1 | 1,260 | 1,100 | −5 | 5 | |
| 26 | 1 | 1,220 | 1,100 | −5 | 5 | |
| 27 | 1 | 1,030 | 1,100 | −5 | 5 | |
| 28 | 1 | 1,100 | 1,100 | −5 | 5 | |
| 29 | 1 | 774 | 1,100 | −5 | 5 | |
| 30 | 1 | 840 | 1,100 | −5 | 5 | |
| 31 | 1 | 874 | 1,100 | −5 | 5 | 1 |
| 32 | 1 | 694 | 1,100 | −5 | 5 | 1 |
| 33 | 1 | 940 | 1,100 | −5 | 5 | 1 |
| 34 | 1 | 833 | 1,100 | −5 | 5 | 1 |
| 35 | 1 | 701 | 1,100 | −5 | 5 | 1 |
| 36 | 1 | 916 | 1,100 | −5 | 5 | 1 |
| 37 | 1 | 692 | 1,100 | −5 | 5 | 1 |
| 38 | 1 | 1,020 | 1,100 | −5 | 5 | 1 |
| 39 | 1 | 1,050 | 1,100 | −5 | 5 | 1 |
| 40 | 1 | 969 | 1,100 | −5 | 5 | 1 |
First 40 of 100 rows.
- σ estimated from all subgroups.
The exact R script · R R version 4.5.1 (2025-06-13)
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec 8de3a8de5321a5b5
# Dataset: q1_nile (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_spc_*(): twin of codesplash.quality.spc (qcc 2.7 conventions)
# Classic equivalent: qcc::qcc(qcc.groups(x, sample), type = "xbar"), qcc(type = "R" | "S" | "xbar.one" |
# "p" | "np" | "c" | "u"), qcc::cusum(), qcc::ewma() — same constants and sigma estimators.
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/q1_nile.parquet", col_select = c("Flow")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("Flow")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("Flow")) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart <- "cusum"
value_col <- "Flow"
subgroup_col <- NULL
size_col <- NULL
phase1 <- as.integer(0)
nsigmas <- 3
rules <- "western_electric"
x <- as.numeric(df[[value_col]])
labels_raw <- if (!is.null(subgroup_col)) as.character(df[[subgroup_col]]) else NULL
attribute <- chart %in% c("p", "np", "c", "u", "laney_p")
if (attribute) {
sizes <- if (!is.null(size_col)) as.numeric(df[[size_col]]) else NULL
if (!is.null(labels_raw)) {
lv <- unique(labels_raw)
d <- vapply(lv, function(l) sum(x[labels_raw == l]), 0)
n_ <- if (!is.null(sizes)) vapply(lv, function(l) sum(sizes[labels_raw == l]), 0) else NULL
labels <- lv
} else {
d <- x; n_ <- sizes; labels <- as.character(seq_along(x))
}
res <- cs_spc_attributes(unname(d), if (is.null(n_)) NULL else unname(n_), chart, phase1, nsigmas)
} else {
sg <- cs_spc_subgroups(x, labels_raw, NULL)
groups <- sg$groups; labels <- sg$labels
if (length(groups) < 2) { # control limits need two subgroups (registry/errors.yaml)
if (!is.null(subgroup_col)) cs_error("CS_E_TOO_FEW_GROUPS", column = subgroup_col, min = 2, k = length(groups))
cs_check_rows(length(x), 2, "A control chart")
}
if (chart == "cusum") {
res <- cs_spc_cusum(groups, phase1, 1100, 5, 1)
} else if (chart == "ewma") {
res <- cs_spc_ewma(groups, phase1, 1100, 0.2, nsigmas)
} else {
if (chart == "imr" && any(lengths(groups) != 1)) stop("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.", call. = FALSE)
res <- cs_spc_variables(groups, chart, phase1, nsigmas)
}
}
m <- length(labels)
# %% Signals
if (chart == "cusum") {
stat <- res$stat
center <- rep(res$center, m)
viol_rules <- lapply(seq_len(m), function(i) if (res$pos[i] > res$h || res$neg[i] < -res$h) 1L else integer())
lcl <- rep(-res$h, m); ucl <- rep(res$h, m)
} else if (chart == "ewma") {
stat <- res$ewma
center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- lapply(seq_len(m), function(i) if (stat[i] > ucl[i] || stat[i] < lcl[i]) 1L else integer())
} else {
stat <- res$stat; center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- cs_spc_rules(stat, center, lcl, ucl, res$sd, rules)
}
violations <- which(lengths(viol_rules) > 0)
sec <- res$secondary
sec_viol <- integer()
if (!is.null(sec)) sec_viol <- which(is.finite(sec$stat) & (sec$stat > sec$ucl | sec$stat < sec$lcl))
# %% Tables and chart
chart_labels <- c(xbar_r = "X̄–R", xbar_s = "X̄–S", imr = "I–MR", p = "p", np = "np", c = "c", u = "u",
laney_p = "Laney p′", cusum = "CUSUM", ewma = "EWMA")
label <- chart_labels[[chart]]
panel <- c(xbar_r = "X̄", xbar_s = "X̄", imr = "Individuals", p = "p", np = "np", c = "c", u = "u", laney_p = "p′",
cusum = "CUSUM", ewma = "EWMA")[[chart]]
rule_text <- vapply(viol_rules, function(r) paste(r, collapse = ","), "")
idx <- seq_len(m)
if (chart == "cusum") {
ch <- data.frame(index = c(idx, idx), value = c(res$pos, res$neg), center = 0, lcl = c(lcl, lcl), ucl = c(ucl, ucl),
violation = c(lengths(viol_rules) > 0, lengths(viol_rules) > 0), rule = c(rule_text, rule_text),
chart = rep(c("C⁺", "C⁻"), each = m), stringsAsFactors = FALSE)
} else {
ch <- data.frame(index = idx, value = stat, center = center, lcl = lcl, ucl = ucl, violation = lengths(viol_rules) > 0,
rule = rule_text, chart = panel, stringsAsFactors = FALSE)
if (!is.null(sec)) ch <- rbind(ch, data.frame(index = idx, value = sec$stat, center = sec$center, lcl = sec$lcl, ucl = sec$ucl,
violation = idx %in% sec_viol, rule = ifelse(idx %in% sec_viol, "1", ""),
chart = sec$label, stringsAsFactors = FALSE))
}
charts <- list(cs_chart(
"control", "control-chart", sprintf("%s chart of %s", label, value_col),
list(index = cs_col(if (!attribute || !is.null(labels_raw)) "Subgroup" else "Sample", ch$index),
value = cs_col(if (chart == "imr") value_col else "Statistic", ch$value),
center = cs_col("Center", ch$center), lcl = cs_col("LCL", ch$lcl), ucl = cs_col("UCL", ch$ucl),
violation = cs_col("Signal", ch$violation, "boolean"), rule = cs_col("Rules", ch$rule, "categorical"),
chart = cs_col("Chart", ch$chart, "categorical"))))
tables <- list(list(
key = "points", title = "Points and limits",
columns = list(list(key = "label", label = "Subgroup", type = "string"), list(key = "n", label = "n", type = "number"),
list(key = "stat", label = "Statistic", type = "number"), list(key = "center", label = "Center", type = "number"),
list(key = "lcl", label = "LCL", type = "number"), list(key = "ucl", label = "UCL", type = "number"),
list(key = "rules", label = "Rules broken", type = "string")),
rows = data.frame(label = labels, n = as.numeric(res$sizes), stat = stat, center = center, lcl = lcl, ucl = ucl,
rules = vapply(viol_rules, function(r) paste(r, collapse = ", "), ""), stringsAsFactors = FALSE)
))
# %% Result
sizes_arr <- as.numeric(res$sizes)
values <- list(
chart = chart, chart_label = label, n_subgroups = m, mean_size = mean(sizes_arr),
center = center[1], sigma = res$sigma,
stat = I(stat), lcl = I(lcl), ucl = I(ucl),
violations = I(violations), violation_rules = I(rule_text[lengths(viol_rules) > 0]), n_signals = length(violations),
sec_stat = if (!is.null(sec)) I(sec$stat) else NULL, sec_center = if (!is.null(sec)) sec$center[1] else NULL,
sec_lcl = if (!is.null(sec)) I(sec$lcl) else NULL, sec_ucl = if (!is.null(sec)) I(sec$ucl) else NULL,
sec_violations = I(sec_viol),
cusum_pos = if (chart == "cusum") I(res$pos) else NULL,
cusum_neg = if (chart == "cusum") I(res$neg) else NULL
)
rule_names <- c(basic = "points beyond the limits", western_electric = "Western Electric rules", nelson = "Nelson rules")
summary <- sprintf("%s chart of %s: %d %s; ", label, value_col, m, if (mean(sizes_arr) != 1) "subgroups" else "points")
summary <- paste0(summary, if (length(violations)) sprintf("%d signal%s (%s).", length(violations), if (length(violations) != 1) "s" else "",
if (chart %in% c("cusum", "ewma")) "beyond the limits" else rule_names[[rules]]) else "no signals.")
notes <- sprintf("σ estimated from %s.", if (phase1 > 0 && phase1 < m) sprintf("the first %d subgroups (phase I)", phase1) else "all subgroups")
if (chart %in% c("xbar_r", "xbar_s", "imr"))
notes <- c(notes, c(xbar_r = "σ = mean(R / d2) (qcc UWAVE-R).", xbar_s = "σ = mean(S / c4) (qcc UWAVE-SD).", imr = "σ = mean moving range / 1.128.")[[chart]])
cs_publish(list(
method = "spc.control_chart",
methodVersion = "1.0.1",
title = sprintf("%s control chart", label),
engine = cs_engine_info("codesplashr", "nanoparquet"),
n = length(x),
summary = summary,
statistics = list(list(key = "center", label = "Center", value = center[1]), list(key = "sigma", label = "σ", value = res$sigma),
list(key = "n_subgroups", label = "Subgroups", value = m, format = "integer"),
list(key = "n_signals", label = "Signals", value = length(violations), format = "integer")),
tables = tables,
charts = charts,
warnings = warnings,
notes = as.list(notes),
values = values
))
CUSUM chart of Flow: 100 points; 70 signals (beyond the limits).
- Center
- 1,100
- σ
- 118.13
- Subgroups
- 100
- Signals
- 70
To keep this page light, the plots are shown once, under the R tab.
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 1 | 1,120 | 1,100 | −5 | 5 | |
| 2 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 3 | 1 | 963 | 1,100 | −5 | 5 | |
| 4 | 1 | 1,210 | 1,100 | −5 | 5 | |
| 5 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 6 | 1 | 1,160 | 1,100 | −5 | 5 | |
| 7 | 1 | 813 | 1,100 | −5 | 5 | |
| 8 | 1 | 1,230 | 1,100 | −5 | 5 | |
| 9 | 1 | 1,370 | 1,100 | −5 | 5 | |
| 10 | 1 | 1,140 | 1,100 | −5 | 5 | |
| 11 | 1 | 995 | 1,100 | −5 | 5 | |
| 12 | 1 | 935 | 1,100 | −5 | 5 | |
| 13 | 1 | 1,110 | 1,100 | −5 | 5 | |
| 14 | 1 | 994 | 1,100 | −5 | 5 | |
| 15 | 1 | 1,020 | 1,100 | −5 | 5 | |
| 16 | 1 | 960 | 1,100 | −5 | 5 | |
| 17 | 1 | 1,180 | 1,100 | −5 | 5 | |
| 18 | 1 | 799 | 1,100 | −5 | 5 | |
| 19 | 1 | 958 | 1,100 | −5 | 5 | |
| 20 | 1 | 1,140 | 1,100 | −5 | 5 | |
| 21 | 1 | 1,100 | 1,100 | −5 | 5 | |
| 22 | 1 | 1,210 | 1,100 | −5 | 5 | |
| 23 | 1 | 1,150 | 1,100 | −5 | 5 | |
| 24 | 1 | 1,250 | 1,100 | −5 | 5 | |
| 25 | 1 | 1,260 | 1,100 | −5 | 5 | |
| 26 | 1 | 1,220 | 1,100 | −5 | 5 | |
| 27 | 1 | 1,030 | 1,100 | −5 | 5 | |
| 28 | 1 | 1,100 | 1,100 | −5 | 5 | |
| 29 | 1 | 774 | 1,100 | −5 | 5 | |
| 30 | 1 | 840 | 1,100 | −5 | 5 | |
| 31 | 1 | 874 | 1,100 | −5 | 5 | 1 |
| 32 | 1 | 694 | 1,100 | −5 | 5 | 1 |
| 33 | 1 | 940 | 1,100 | −5 | 5 | 1 |
| 34 | 1 | 833 | 1,100 | −5 | 5 | 1 |
| 35 | 1 | 701 | 1,100 | −5 | 5 | 1 |
| 36 | 1 | 916 | 1,100 | −5 | 5 | 1 |
| 37 | 1 | 692 | 1,100 | −5 | 5 | 1 |
| 38 | 1 | 1,020 | 1,100 | −5 | 5 | 1 |
| 39 | 1 | 1,050 | 1,100 | −5 | 5 | 1 |
| 40 | 1 | 969 | 1,100 | −5 | 5 | 1 |
First 40 of 100 rows.
- σ estimated from all subgroups.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec 8de3a8de5321a5b5
# Dataset: q1_nile (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.quality import spc # twin of codesplashr::cs_spc_* (qcc 2.7 conventions)
# Classic equivalent in R: qcc::qcc(data, type = "xbar" | "R" | "S" | "xbar.one" | "p" | "np" | "c" | "u"),
# qcc::cusum(), qcc::ewma(). Python has no maintained SPC library with the same constants.
# %% Data
df = pd.read_parquet("tests/parity/fixtures/q1_nile.parquet", columns=["Flow"])
n_input = len(df)
df = df.dropna(subset=["Flow"]) # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["Flow"]) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart = "cusum"
value_col = "Flow"
subgroup_col = None
size_col = None
phase1 = int(0)
nsigmas = 3
rules = "western_electric"
x = df[value_col].to_numpy(dtype=float)
def _label(v):
return str(int(v)) if isinstance(v, float) and v.is_integer() else str(v)
labels_raw = [_label(v) for v in df[subgroup_col]] if subgroup_col else None
attribute = chart in ("p", "np", "c", "u", "laney_p")
if attribute:
sizes = df[size_col].to_numpy(dtype=float) if size_col else None
if labels_raw is not None:
order = list(dict.fromkeys(labels_raw))
d = np.asarray([x[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order])
n_ = np.asarray([sizes[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order]) if sizes is not None else None
labels = order
else:
d, n_, labels = x, sizes, [str(i + 1) for i in range(len(x))]
res = spc.attributes_chart(d, n_, chart, phase1, nsigmas)
else:
groups, labels = spc.subgroups(x, labels_raw, None)
if len(groups) < 2: # control limits need two subgroups (registry/errors.yaml)
if subgroup_col:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=subgroup_col, min=2, k=len(groups))
cs.check_rows(len(x), 2, "A control chart")
if chart == "cusum":
res = spc.cusum(groups, phase1, 1100, 5, 1)
elif chart == "ewma":
res = spc.ewma(groups, phase1, 1100, 0.2, nsigmas)
else:
if chart == "imr" and any(len(g) != 1 for g in groups):
raise ValueError("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.")
res = spc.variables_chart(groups, chart, phase1, nsigmas)
m = len(labels)
# %% Signals
if chart == "cusum":
stat = res["stat"]
center = np.full(m, res["center"])
viol_rules = [[1] if (res["pos"][i] > res["h"] or res["neg"][i] < -res["h"]) else [] for i in range(m)]
lcl = np.full(m, -res["h"])
ucl = np.full(m, res["h"])
elif chart == "ewma":
stat = res["ewma"]
center, lcl, ucl = res["center"], res["lcl"], res["ucl"]
viol_rules = [[1] if (stat[i] > ucl[i] or stat[i] < lcl[i]) else [] for i in range(m)]
else:
stat, center, lcl, ucl = res["stat"], res["center"], res["lcl"], res["ucl"]
viol_rules = spc.run_rules(stat, center, lcl, ucl, res["sd"], rules)
violations = [i + 1 for i in range(m) if viol_rules[i]]
sec = res.get("secondary")
sec_viol = []
if sec:
s_ok = np.isfinite(sec["stat"])
sec_viol = [i + 1 for i in range(m) if s_ok[i] and (sec["stat"][i] > sec["ucl"][i] or sec["stat"][i] < sec["lcl"][i])]
# %% Tables and chart
label = spc.CHART_LABEL[chart]
idx = list(range(1, m + 1))
panel = {"xbar_r": "X̄", "xbar_s": "X̄", "imr": "Individuals", "p": "p", "np": "np", "c": "c", "u": "u", "laney_p": "p′", "cusum": "CUSUM", "ewma": "EWMA"}[chart]
rows_idx, rows_val, rows_c, rows_l, rows_u, rows_v, rows_r, rows_f = [], [], [], [], [], [], [], []
if chart == "cusum":
for name, series in (("C⁺", res["pos"]), ("C⁻", res["neg"])):
rows_idx += idx; rows_val += list(map(float, series)); rows_c += [0.0] * m; rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [name] * m
else:
rows_idx += idx; rows_val += list(map(float, stat)); rows_c += list(map(float, center)); rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [panel] * m
if sec:
rows_idx += idx; rows_val += list(map(float, sec["stat"])); rows_c += list(map(float, sec["center"])); rows_l += list(map(float, sec["lcl"]))
rows_u += list(map(float, sec["ucl"])); rows_v += [i + 1 in sec_viol for i in range(m)]; rows_r += ["1" if i + 1 in sec_viol else "" for i in range(m)]
rows_f += [sec["label"]] * m
charts = [cs.chart(
"control", "control-chart", f"{label} chart of {value_col}",
{"index": cs.col("Subgroup" if not attribute or labels_raw else "Sample", rows_idx),
"value": cs.col(value_col if chart in ("imr",) else "Statistic", rows_val),
"center": cs.col("Center", rows_c), "lcl": cs.col("LCL", rows_l), "ucl": cs.col("UCL", rows_u),
"violation": cs.col("Signal", rows_v, "boolean"), "rule": cs.col("Rules", rows_r, "categorical"),
"chart": cs.col("Chart", rows_f, "categorical")},
)]
table_rows = []
for i in range(m):
table_rows.append({"label": labels[i], "n": float(res["sizes"][i]) if res.get("sizes") is not None else None, "stat": float(stat[i]),
"center": float(center[i]), "lcl": float(lcl[i]), "ucl": float(ucl[i]), "rules": ", ".join(map(str, viol_rules[i]))})
tables = [{
"key": "points", "title": "Points and limits",
"columns": [{"key": "label", "label": "Subgroup", "type": "string"}, {"key": "n", "label": "n", "type": "number"},
{"key": "stat", "label": "Statistic", "type": "number"}, {"key": "center", "label": "Center", "type": "number"},
{"key": "lcl", "label": "LCL", "type": "number"}, {"key": "ucl", "label": "UCL", "type": "number"},
{"key": "rules", "label": "Rules broken", "type": "string"}],
"rows": table_rows,
}]
# %% Result
sizes_arr = np.asarray(res["sizes"], dtype=float)
values = {
"chart": chart, "chart_label": label, "n_subgroups": m, "mean_size": float(np.mean(sizes_arr)),
"center": float(center[0]), "sigma": float(res["sigma"]),
"stat": list(map(float, stat)), "lcl": list(map(float, lcl)), "ucl": list(map(float, ucl)),
"violations": violations, "violation_rules": [",".join(map(str, r)) for r in viol_rules if r], "n_signals": len(violations),
"sec_stat": list(map(float, sec["stat"])) if sec else None, "sec_center": float(sec["center"][0]) if sec else None,
"sec_lcl": list(map(float, sec["lcl"])) if sec else None, "sec_ucl": list(map(float, sec["ucl"])) if sec else None,
"sec_violations": sec_viol,
"cusum_pos": list(map(float, res["pos"])) if chart == "cusum" else None,
"cusum_neg": list(map(float, res["neg"])) if chart == "cusum" else None,
}
rule_names = {"basic": "points beyond the limits", "western_electric": "Western Electric rules", "nelson": "Nelson rules"}
summary = f"{label} chart of {value_col}: {m} {'subgroups' if np.mean(sizes_arr) != 1 else 'points'}; "
summary += f"{len(violations)} signal{'s' if len(violations) != 1 else ''} ({rule_names[rules] if chart not in ('cusum', 'ewma') else 'beyond the limits'})." if violations else "no signals."
notes = [f"σ estimated from {'the first ' + str(phase1) + ' subgroups (phase I)' if 0 < phase1 < m else 'all subgroups'}."]
if chart in ("xbar_r", "xbar_s", "imr"):
notes.append({"xbar_r": "σ = mean(R / d2) (qcc UWAVE-R).", "xbar_s": "σ = mean(S / c4) (qcc UWAVE-SD).", "imr": "σ = mean moving range / 1.128."}[chart])
cs.publish({
"title": f"{label} control chart",
"engine": cs.engine_info("numpy", "pandas"),
"n": len(x),
"summary": summary,
"statistics": [
{"key": "center", "label": "Center", "value": float(center[0])},
{"key": "sigma", "label": "σ", "value": float(res["sigma"])},
{"key": "n_subgroups", "label": "Subgroups", "value": m, "format": "integer"},
{"key": "n_signals", "label": "Signals", "value": len(violations), "format": "integer"},
],
"tables": tables,
"charts": charts,
"warnings": warnings,
"notes": notes,
"values": values,
})
The target here is 1,100, so a flow persistently below it builds up in the lower sum. 70 points signal. The sum crosses its limit partway through, and it stays out. So look for where the climb starts, because the total only says that something has been wrong for a while.
Weight the recent past
PredictPredict first
You want to detect a small, sustained shift. Which weight is better?
Reveal
Smaller : it remembers more of the past, so small shifts add up. A larger reacts faster to big jumps and behaves more like an ordinary chart. With , it is one.
See an EWMA
In the appEWMA chart of Diameter (mm): 40 subgroups; 4 signals (beyond the limits).
- Center
- 74.004
- σ
- 0.0101
- Subgroups
- 40
- Signals
- 4
Plots
View data
| Center | Chart | Subgroup | LCL | Rules | UCL | Statistic | Signal |
|---|---|---|---|---|---|---|---|
| 74.004 | EWMA | 1 | 74.000 | 74.008 | 74.006 | false | |
| 74.004 | EWMA | 2 | 73.999 | 74.009 | 74.004 | false | |
| 74.004 | EWMA | 3 | 73.998 | 74.009 | 74.005 | false | |
| 74.004 | EWMA | 4 | 73.998 | 74.009 | 74.005 | false | |
| 74.004 | EWMA | 5 | 73.998 | 74.009 | 74.004 | false | |
| 74.004 | EWMA | 6 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 7 | 73.998 | 74.009 | 74.001 | false | |
| 74.004 | EWMA | 8 | 73.998 | 74.009 | 74.000 | false | |
| 74.004 | EWMA | 9 | 73.998 | 74.009 | 74.001 | false | |
| 74.004 | EWMA | 10 | 73.998 | 74.009 | 74.000 | false | |
| 74.004 | EWMA | 11 | 73.998 | 74.009 | 73.998 | false | |
| 74.004 | EWMA | 12 | 73.998 | 74.009 | 73.999 | false | |
| 74.004 | EWMA | 13 | 73.998 | 74.009 | 73.999 | false | |
| 74.004 | EWMA | 14 | 73.998 | 1 | 74.009 | 73.996 | true |
| 74.004 | EWMA | 15 | 73.998 | 74.009 | 73.999 | false | |
| 74.004 | EWMA | 16 | 73.998 | 74.009 | 73.998 | false | |
| 74.004 | EWMA | 17 | 73.998 | 74.009 | 73.999 | false | |
| 74.004 | EWMA | 18 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 19 | 73.998 | 74.009 | 74.001 | false | |
| 74.004 | EWMA | 20 | 73.998 | 74.009 | 74.003 | false | |
| 74.004 | EWMA | 21 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 22 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 23 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 24 | 73.998 | 74.009 | 74.003 | false | |
| 74.004 | EWMA | 25 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 26 | 73.998 | 74.009 | 74.004 | false | |
| 74.004 | EWMA | 27 | 73.998 | 74.009 | 74.003 | false | |
| 74.004 | EWMA | 28 | 73.998 | 74.009 | 74.000 | false | |
| 74.004 | EWMA | 29 | 73.998 | 74.009 | 74.001 | false | |
| 74.004 | EWMA | 30 | 73.998 | 74.009 | 74.000 | false | |
| 74.004 | EWMA | 31 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 32 | 73.998 | 74.009 | 74.003 | false | |
| 74.004 | EWMA | 33 | 73.998 | 74.009 | 74.002 | false | |
| 74.004 | EWMA | 34 | 73.998 | 74.009 | 74.004 | false | |
| 74.004 | EWMA | 35 | 73.998 | 74.009 | 74.007 | false | |
| 74.004 | EWMA | 36 | 73.998 | 74.009 | 74.006 | false | |
| 74.004 | EWMA | 37 | 73.998 | 74.009 | 74.009 | false | |
| 74.004 | EWMA | 38 | 73.998 | 1 | 74.009 | 74.012 | true |
| 74.004 | EWMA | 39 | 73.998 | 1 | 74.009 | 74.016 | true |
| 74.004 | EWMA | 40 | 73.998 | 1 | 74.009 | 74.015 | true |
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 5 | 74.006 | 74.004 | 74.000 | 74.008 | |
| 2 | 5 | 74.004 | 74.004 | 73.999 | 74.009 | |
| 3 | 5 | 74.005 | 74.004 | 73.998 | 74.009 | |
| 4 | 5 | 74.005 | 74.004 | 73.998 | 74.009 | |
| 5 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 6 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 7 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 8 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 9 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 10 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 11 | 5 | 73.998 | 74.004 | 73.998 | 74.009 | |
| 12 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 13 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 14 | 5 | 73.996 | 74.004 | 73.998 | 74.009 | 1 |
| 15 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 16 | 5 | 73.998 | 74.004 | 73.998 | 74.009 | |
| 17 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 18 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 19 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 20 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 21 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 22 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 23 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 24 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 25 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 26 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 27 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 28 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 29 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 30 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 31 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 32 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 33 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 34 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 35 | 5 | 74.007 | 74.004 | 73.998 | 74.009 | |
| 36 | 5 | 74.006 | 74.004 | 73.998 | 74.009 | |
| 37 | 5 | 74.009 | 74.004 | 73.998 | 74.009 | |
| 38 | 5 | 74.012 | 74.004 | 73.998 | 74.009 | 1 |
| 39 | 5 | 74.016 | 74.004 | 73.998 | 74.009 | 1 |
| 40 | 5 | 74.015 | 74.004 | 73.998 | 74.009 | 1 |
- σ estimated from all subgroups.
The exact R script · R R version 4.5.1 (2025-06-13)
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec 2f20d02a55798c54
# Dataset: q1_pistonrings (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_spc_*(): twin of codesplash.quality.spc (qcc 2.7 conventions)
# Classic equivalent: qcc::qcc(qcc.groups(x, sample), type = "xbar"), qcc(type = "R" | "S" | "xbar.one" |
# "p" | "np" | "c" | "u"), qcc::cusum(), qcc::ewma() — same constants and sigma estimators.
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/q1_pistonrings.parquet", col_select = c("Diameter (mm)", "Sample")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("Diameter (mm)", "Sample")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("Diameter (mm)", "Sample")) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart <- "ewma"
value_col <- "Diameter (mm)"
subgroup_col <- "Sample"
size_col <- NULL
phase1 <- as.integer(0)
nsigmas <- 3
rules <- "western_electric"
x <- as.numeric(df[[value_col]])
labels_raw <- if (!is.null(subgroup_col)) as.character(df[[subgroup_col]]) else NULL
attribute <- chart %in% c("p", "np", "c", "u", "laney_p")
if (attribute) {
sizes <- if (!is.null(size_col)) as.numeric(df[[size_col]]) else NULL
if (!is.null(labels_raw)) {
lv <- unique(labels_raw)
d <- vapply(lv, function(l) sum(x[labels_raw == l]), 0)
n_ <- if (!is.null(sizes)) vapply(lv, function(l) sum(sizes[labels_raw == l]), 0) else NULL
labels <- lv
} else {
d <- x; n_ <- sizes; labels <- as.character(seq_along(x))
}
res <- cs_spc_attributes(unname(d), if (is.null(n_)) NULL else unname(n_), chart, phase1, nsigmas)
} else {
sg <- cs_spc_subgroups(x, labels_raw, NULL)
groups <- sg$groups; labels <- sg$labels
if (length(groups) < 2) { # control limits need two subgroups (registry/errors.yaml)
if (!is.null(subgroup_col)) cs_error("CS_E_TOO_FEW_GROUPS", column = subgroup_col, min = 2, k = length(groups))
cs_check_rows(length(x), 2, "A control chart")
}
if (chart == "cusum") {
res <- cs_spc_cusum(groups, phase1, NULL, 5, 1)
} else if (chart == "ewma") {
res <- cs_spc_ewma(groups, phase1, NULL, 0.3, nsigmas)
} else {
if (chart == "imr" && any(lengths(groups) != 1)) stop("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.", call. = FALSE)
res <- cs_spc_variables(groups, chart, phase1, nsigmas)
}
}
m <- length(labels)
# %% Signals
if (chart == "cusum") {
stat <- res$stat
center <- rep(res$center, m)
viol_rules <- lapply(seq_len(m), function(i) if (res$pos[i] > res$h || res$neg[i] < -res$h) 1L else integer())
lcl <- rep(-res$h, m); ucl <- rep(res$h, m)
} else if (chart == "ewma") {
stat <- res$ewma
center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- lapply(seq_len(m), function(i) if (stat[i] > ucl[i] || stat[i] < lcl[i]) 1L else integer())
} else {
stat <- res$stat; center <- res$center; lcl <- res$lcl; ucl <- res$ucl
viol_rules <- cs_spc_rules(stat, center, lcl, ucl, res$sd, rules)
}
violations <- which(lengths(viol_rules) > 0)
sec <- res$secondary
sec_viol <- integer()
if (!is.null(sec)) sec_viol <- which(is.finite(sec$stat) & (sec$stat > sec$ucl | sec$stat < sec$lcl))
# %% Tables and chart
chart_labels <- c(xbar_r = "X̄–R", xbar_s = "X̄–S", imr = "I–MR", p = "p", np = "np", c = "c", u = "u",
laney_p = "Laney p′", cusum = "CUSUM", ewma = "EWMA")
label <- chart_labels[[chart]]
panel <- c(xbar_r = "X̄", xbar_s = "X̄", imr = "Individuals", p = "p", np = "np", c = "c", u = "u", laney_p = "p′",
cusum = "CUSUM", ewma = "EWMA")[[chart]]
rule_text <- vapply(viol_rules, function(r) paste(r, collapse = ","), "")
idx <- seq_len(m)
if (chart == "cusum") {
ch <- data.frame(index = c(idx, idx), value = c(res$pos, res$neg), center = 0, lcl = c(lcl, lcl), ucl = c(ucl, ucl),
violation = c(lengths(viol_rules) > 0, lengths(viol_rules) > 0), rule = c(rule_text, rule_text),
chart = rep(c("C⁺", "C⁻"), each = m), stringsAsFactors = FALSE)
} else {
ch <- data.frame(index = idx, value = stat, center = center, lcl = lcl, ucl = ucl, violation = lengths(viol_rules) > 0,
rule = rule_text, chart = panel, stringsAsFactors = FALSE)
if (!is.null(sec)) ch <- rbind(ch, data.frame(index = idx, value = sec$stat, center = sec$center, lcl = sec$lcl, ucl = sec$ucl,
violation = idx %in% sec_viol, rule = ifelse(idx %in% sec_viol, "1", ""),
chart = sec$label, stringsAsFactors = FALSE))
}
charts <- list(cs_chart(
"control", "control-chart", sprintf("%s chart of %s", label, value_col),
list(index = cs_col(if (!attribute || !is.null(labels_raw)) "Subgroup" else "Sample", ch$index),
value = cs_col(if (chart == "imr") value_col else "Statistic", ch$value),
center = cs_col("Center", ch$center), lcl = cs_col("LCL", ch$lcl), ucl = cs_col("UCL", ch$ucl),
violation = cs_col("Signal", ch$violation, "boolean"), rule = cs_col("Rules", ch$rule, "categorical"),
chart = cs_col("Chart", ch$chart, "categorical"))))
tables <- list(list(
key = "points", title = "Points and limits",
columns = list(list(key = "label", label = "Subgroup", type = "string"), list(key = "n", label = "n", type = "number"),
list(key = "stat", label = "Statistic", type = "number"), list(key = "center", label = "Center", type = "number"),
list(key = "lcl", label = "LCL", type = "number"), list(key = "ucl", label = "UCL", type = "number"),
list(key = "rules", label = "Rules broken", type = "string")),
rows = data.frame(label = labels, n = as.numeric(res$sizes), stat = stat, center = center, lcl = lcl, ucl = ucl,
rules = vapply(viol_rules, function(r) paste(r, collapse = ", "), ""), stringsAsFactors = FALSE)
))
# %% Result
sizes_arr <- as.numeric(res$sizes)
values <- list(
chart = chart, chart_label = label, n_subgroups = m, mean_size = mean(sizes_arr),
center = center[1], sigma = res$sigma,
stat = I(stat), lcl = I(lcl), ucl = I(ucl),
violations = I(violations), violation_rules = I(rule_text[lengths(viol_rules) > 0]), n_signals = length(violations),
sec_stat = if (!is.null(sec)) I(sec$stat) else NULL, sec_center = if (!is.null(sec)) sec$center[1] else NULL,
sec_lcl = if (!is.null(sec)) I(sec$lcl) else NULL, sec_ucl = if (!is.null(sec)) I(sec$ucl) else NULL,
sec_violations = I(sec_viol),
cusum_pos = if (chart == "cusum") I(res$pos) else NULL,
cusum_neg = if (chart == "cusum") I(res$neg) else NULL
)
rule_names <- c(basic = "points beyond the limits", western_electric = "Western Electric rules", nelson = "Nelson rules")
summary <- sprintf("%s chart of %s: %d %s; ", label, value_col, m, if (mean(sizes_arr) != 1) "subgroups" else "points")
summary <- paste0(summary, if (length(violations)) sprintf("%d signal%s (%s).", length(violations), if (length(violations) != 1) "s" else "",
if (chart %in% c("cusum", "ewma")) "beyond the limits" else rule_names[[rules]]) else "no signals.")
notes <- sprintf("σ estimated from %s.", if (phase1 > 0 && phase1 < m) sprintf("the first %d subgroups (phase I)", phase1) else "all subgroups")
if (chart %in% c("xbar_r", "xbar_s", "imr"))
notes <- c(notes, c(xbar_r = "σ = mean(R / d2) (qcc UWAVE-R).", xbar_s = "σ = mean(S / c4) (qcc UWAVE-SD).", imr = "σ = mean moving range / 1.128.")[[chart]])
cs_publish(list(
method = "spc.control_chart",
methodVersion = "1.0.1",
title = sprintf("%s control chart", label),
engine = cs_engine_info("codesplashr", "nanoparquet"),
n = length(x),
summary = summary,
statistics = list(list(key = "center", label = "Center", value = center[1]), list(key = "sigma", label = "σ", value = res$sigma),
list(key = "n_subgroups", label = "Subgroups", value = m, format = "integer"),
list(key = "n_signals", label = "Signals", value = length(violations), format = "integer")),
tables = tables,
charts = charts,
warnings = warnings,
notes = as.list(notes),
values = values
))
EWMA chart of Diameter (mm): 40 subgroups; 4 signals (beyond the limits).
- Center
- 74.004
- σ
- 0.0101
- Subgroups
- 40
- Signals
- 4
To keep this page light, the plots are shown once, under the R tab.
Points and limits
| Subgroup | n | Statistic | Center | LCL | UCL | Rules broken |
|---|---|---|---|---|---|---|
| 1 | 5 | 74.006 | 74.004 | 74.000 | 74.008 | |
| 2 | 5 | 74.004 | 74.004 | 73.999 | 74.009 | |
| 3 | 5 | 74.005 | 74.004 | 73.998 | 74.009 | |
| 4 | 5 | 74.005 | 74.004 | 73.998 | 74.009 | |
| 5 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 6 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 7 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 8 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 9 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 10 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 11 | 5 | 73.998 | 74.004 | 73.998 | 74.009 | |
| 12 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 13 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 14 | 5 | 73.996 | 74.004 | 73.998 | 74.009 | 1 |
| 15 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 16 | 5 | 73.998 | 74.004 | 73.998 | 74.009 | |
| 17 | 5 | 73.999 | 74.004 | 73.998 | 74.009 | |
| 18 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 19 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 20 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 21 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 22 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 23 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 24 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 25 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 26 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 27 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 28 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 29 | 5 | 74.001 | 74.004 | 73.998 | 74.009 | |
| 30 | 5 | 74.000 | 74.004 | 73.998 | 74.009 | |
| 31 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 32 | 5 | 74.003 | 74.004 | 73.998 | 74.009 | |
| 33 | 5 | 74.002 | 74.004 | 73.998 | 74.009 | |
| 34 | 5 | 74.004 | 74.004 | 73.998 | 74.009 | |
| 35 | 5 | 74.007 | 74.004 | 73.998 | 74.009 | |
| 36 | 5 | 74.006 | 74.004 | 73.998 | 74.009 | |
| 37 | 5 | 74.009 | 74.004 | 73.998 | 74.009 | |
| 38 | 5 | 74.012 | 74.004 | 73.998 | 74.009 | 1 |
| 39 | 5 | 74.016 | 74.004 | 73.998 | 74.009 | 1 |
| 40 | 5 | 74.015 | 74.004 | 73.998 | 74.009 | 1 |
- σ estimated from all subgroups.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Control chart (X̄–R, X̄–S, I–MR, p, np, c, u, Laney p′, CUSUM, EWMA)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method spc.control_chart 1.0.1 · spec 2f20d02a55798c54
# Dataset: q1_pistonrings (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.quality import spc # twin of codesplashr::cs_spc_* (qcc 2.7 conventions)
# Classic equivalent in R: qcc::qcc(data, type = "xbar" | "R" | "S" | "xbar.one" | "p" | "np" | "c" | "u"),
# qcc::cusum(), qcc::ewma(). Python has no maintained SPC library with the same constants.
# %% Data
df = pd.read_parquet("tests/parity/fixtures/q1_pistonrings.parquet", columns=["Diameter (mm)", "Sample"])
n_input = len(df)
df = df.dropna(subset=["Diameter (mm)", "Sample"]) # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["Diameter (mm)", "Sample"]) # infinite values stop the run (registry/errors.yaml)
# %% Subgroups
chart = "ewma"
value_col = "Diameter (mm)"
subgroup_col = "Sample"
size_col = None
phase1 = int(0)
nsigmas = 3
rules = "western_electric"
x = df[value_col].to_numpy(dtype=float)
def _label(v):
return str(int(v)) if isinstance(v, float) and v.is_integer() else str(v)
labels_raw = [_label(v) for v in df[subgroup_col]] if subgroup_col else None
attribute = chart in ("p", "np", "c", "u", "laney_p")
if attribute:
sizes = df[size_col].to_numpy(dtype=float) if size_col else None
if labels_raw is not None:
order = list(dict.fromkeys(labels_raw))
d = np.asarray([x[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order])
n_ = np.asarray([sizes[[i for i, l in enumerate(labels_raw) if l == lv]].sum() for lv in order]) if sizes is not None else None
labels = order
else:
d, n_, labels = x, sizes, [str(i + 1) for i in range(len(x))]
res = spc.attributes_chart(d, n_, chart, phase1, nsigmas)
else:
groups, labels = spc.subgroups(x, labels_raw, None)
if len(groups) < 2: # control limits need two subgroups (registry/errors.yaml)
if subgroup_col:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=subgroup_col, min=2, k=len(groups))
cs.check_rows(len(x), 2, "A control chart")
if chart == "cusum":
res = spc.cusum(groups, phase1, None, 5, 1)
elif chart == "ewma":
res = spc.ewma(groups, phase1, None, 0.3, nsigmas)
else:
if chart == "imr" and any(len(g) != 1 for g in groups):
raise ValueError("I–MR charts use one value per row; choose X̄–R or X̄–S for subgroups.")
res = spc.variables_chart(groups, chart, phase1, nsigmas)
m = len(labels)
# %% Signals
if chart == "cusum":
stat = res["stat"]
center = np.full(m, res["center"])
viol_rules = [[1] if (res["pos"][i] > res["h"] or res["neg"][i] < -res["h"]) else [] for i in range(m)]
lcl = np.full(m, -res["h"])
ucl = np.full(m, res["h"])
elif chart == "ewma":
stat = res["ewma"]
center, lcl, ucl = res["center"], res["lcl"], res["ucl"]
viol_rules = [[1] if (stat[i] > ucl[i] or stat[i] < lcl[i]) else [] for i in range(m)]
else:
stat, center, lcl, ucl = res["stat"], res["center"], res["lcl"], res["ucl"]
viol_rules = spc.run_rules(stat, center, lcl, ucl, res["sd"], rules)
violations = [i + 1 for i in range(m) if viol_rules[i]]
sec = res.get("secondary")
sec_viol = []
if sec:
s_ok = np.isfinite(sec["stat"])
sec_viol = [i + 1 for i in range(m) if s_ok[i] and (sec["stat"][i] > sec["ucl"][i] or sec["stat"][i] < sec["lcl"][i])]
# %% Tables and chart
label = spc.CHART_LABEL[chart]
idx = list(range(1, m + 1))
panel = {"xbar_r": "X̄", "xbar_s": "X̄", "imr": "Individuals", "p": "p", "np": "np", "c": "c", "u": "u", "laney_p": "p′", "cusum": "CUSUM", "ewma": "EWMA"}[chart]
rows_idx, rows_val, rows_c, rows_l, rows_u, rows_v, rows_r, rows_f = [], [], [], [], [], [], [], []
if chart == "cusum":
for name, series in (("C⁺", res["pos"]), ("C⁻", res["neg"])):
rows_idx += idx; rows_val += list(map(float, series)); rows_c += [0.0] * m; rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [name] * m
else:
rows_idx += idx; rows_val += list(map(float, stat)); rows_c += list(map(float, center)); rows_l += list(map(float, lcl)); rows_u += list(map(float, ucl))
rows_v += [bool(viol_rules[i]) for i in range(m)]; rows_r += [",".join(map(str, viol_rules[i])) for i in range(m)]; rows_f += [panel] * m
if sec:
rows_idx += idx; rows_val += list(map(float, sec["stat"])); rows_c += list(map(float, sec["center"])); rows_l += list(map(float, sec["lcl"]))
rows_u += list(map(float, sec["ucl"])); rows_v += [i + 1 in sec_viol for i in range(m)]; rows_r += ["1" if i + 1 in sec_viol else "" for i in range(m)]
rows_f += [sec["label"]] * m
charts = [cs.chart(
"control", "control-chart", f"{label} chart of {value_col}",
{"index": cs.col("Subgroup" if not attribute or labels_raw else "Sample", rows_idx),
"value": cs.col(value_col if chart in ("imr",) else "Statistic", rows_val),
"center": cs.col("Center", rows_c), "lcl": cs.col("LCL", rows_l), "ucl": cs.col("UCL", rows_u),
"violation": cs.col("Signal", rows_v, "boolean"), "rule": cs.col("Rules", rows_r, "categorical"),
"chart": cs.col("Chart", rows_f, "categorical")},
)]
table_rows = []
for i in range(m):
table_rows.append({"label": labels[i], "n": float(res["sizes"][i]) if res.get("sizes") is not None else None, "stat": float(stat[i]),
"center": float(center[i]), "lcl": float(lcl[i]), "ucl": float(ucl[i]), "rules": ", ".join(map(str, viol_rules[i]))})
tables = [{
"key": "points", "title": "Points and limits",
"columns": [{"key": "label", "label": "Subgroup", "type": "string"}, {"key": "n", "label": "n", "type": "number"},
{"key": "stat", "label": "Statistic", "type": "number"}, {"key": "center", "label": "Center", "type": "number"},
{"key": "lcl", "label": "LCL", "type": "number"}, {"key": "ucl", "label": "UCL", "type": "number"},
{"key": "rules", "label": "Rules broken", "type": "string"}],
"rows": table_rows,
}]
# %% Result
sizes_arr = np.asarray(res["sizes"], dtype=float)
values = {
"chart": chart, "chart_label": label, "n_subgroups": m, "mean_size": float(np.mean(sizes_arr)),
"center": float(center[0]), "sigma": float(res["sigma"]),
"stat": list(map(float, stat)), "lcl": list(map(float, lcl)), "ucl": list(map(float, ucl)),
"violations": violations, "violation_rules": [",".join(map(str, r)) for r in viol_rules if r], "n_signals": len(violations),
"sec_stat": list(map(float, sec["stat"])) if sec else None, "sec_center": float(sec["center"][0]) if sec else None,
"sec_lcl": list(map(float, sec["lcl"])) if sec else None, "sec_ucl": list(map(float, sec["ucl"])) if sec else None,
"sec_violations": sec_viol,
"cusum_pos": list(map(float, res["pos"])) if chart == "cusum" else None,
"cusum_neg": list(map(float, res["neg"])) if chart == "cusum" else None,
}
rule_names = {"basic": "points beyond the limits", "western_electric": "Western Electric rules", "nelson": "Nelson rules"}
summary = f"{label} chart of {value_col}: {m} {'subgroups' if np.mean(sizes_arr) != 1 else 'points'}; "
summary += f"{len(violations)} signal{'s' if len(violations) != 1 else ''} ({rule_names[rules] if chart not in ('cusum', 'ewma') else 'beyond the limits'})." if violations else "no signals."
notes = [f"σ estimated from {'the first ' + str(phase1) + ' subgroups (phase I)' if 0 < phase1 < m else 'all subgroups'}."]
if chart in ("xbar_r", "xbar_s", "imr"):
notes.append({"xbar_r": "σ = mean(R / d2) (qcc UWAVE-R).", "xbar_s": "σ = mean(S / c4) (qcc UWAVE-SD).", "imr": "σ = mean moving range / 1.128."}[chart])
cs.publish({
"title": f"{label} control chart",
"engine": cs.engine_info("numpy", "pandas"),
"n": len(x),
"summary": summary,
"statistics": [
{"key": "center", "label": "Center", "value": float(center[0])},
{"key": "sigma", "label": "σ", "value": float(res["sigma"])},
{"key": "n_subgroups", "label": "Subgroups", "value": m, "format": "integer"},
{"key": "n_signals", "label": "Signals", "value": len(violations), "format": "integer"},
],
"tables": tables,
"charts": charts,
"warnings": warnings,
"notes": notes,
"values": values,
})
This is the piston ring process again, with and limits from all the subgroups. The chart has 4 signals, and the chart's limits fan out over the first few points before settling.
Check your understanding
CheckpointCheck yourself
You run a CUSUM with a target that's far from where the process has ever been. What will it show?
Show the answer
Answer: b
A CUSUM measures departure from your target. Choose a target that means something: the design value, or a stable baseline.
Check yourself
Your process rarely jumps but sometimes drifts by half a sigma. Which chart suits it best?
Show the answer
Answer: b
Both accumulate evidence, which suits small sustained changes. A three-sigma rule alone would take a long time to notice.
Check yourself
Measurements taken seconds apart are strongly autocorrelated. How will a standard control chart behave?
Show the answer
Answer: a
Sample less often, or model the dependence first. The studio's Trend & change step and the time series tools can help.
When did it change?
ReflectAccumulating charts say that a shift happened, and only roughly when. The Trend & change step in the Quality studio answers more directly:
- Slow drift tests for a monotonic trend in production order, and estimates its slope.
- Sudden shift tests for a shift in level, and shows where it most likely happened.
Think of a process you know. Would a change arrive as a jump or as a creep?
Try it
In the appIn the Quality studio, choose Process monitoring, and on the Control chart step pick CUSUM or EWMA.
Recap
Recap- A chart with no memory is slow to catch small shifts. Run rules help a little.
- CUSUM adds up departures from a target, so the target must mean something.
- A smaller EWMA weight remembers more and catches smaller shifts.
- All these charts assume independent points.
Concepts in this lesson