# FiWiControl SPC — Shewhart and Hotelling *T*² **Package:** `**fiwicontrol.spc`** **Implementation:** `**src/fiwicontrol/spc/`** (`shewhart.py`, `hotelling.py`; lazy exports from `**fiwicontrol/spc/__init__.py*`*) Small **statistical process control (SPC)** building blocks for lab metrics: a univariate **Shewhart**-style individuals chart (moving-range dispersion) and a multivariate **Hotelling T²** object with a Phase II upper control limit. --- ## Install SPC uses **NumPy** and **SciPy** (not bundled in the base `**fiwicontrol`** install): ```bash cd ~/Code/FiWiControl python3 -m pip install -e ".[spc]" ``` `**import fiwicontrol.spc**` does not load **NumPy** / **SciPy** until you access `**ShewhartControlChart`** (NumPy only) or `**HotellingT2`** (both). --- ## Classes ### `ShewhartControlChart` - `**ShewhartControlChart(k=3.0)**` — chart width in multiples of estimated sigma. - `**fit_individuals(x, moving_range_span=2)**` — Phase I fit from a 1-D `**numpy**` array; only `**moving_range_span=2**` is supported (average moving range of consecutive pairs, `**d₂ = 1.128**`). - `**limits()**` → `**(LCL, center, UCL)**` with width `**k**` sigma (default `**k=3.0**`). - `**is_out_of_control(value)**` — boolean vs those limits. ### `HotellingT2` - `**fit(X)**` — `**X**` shape `**(m, p)**` with `**m > p + 1**`; unbiased sample covariance, inverse for *T*². - `**mean_`**, `**covariance_*`* — fitted Phase I mean vector and covariance (after `**fit**`). - `**t2(x)**` — Hotelling statistic for one observation `**x**` of length `**p**` vs the fitted mean. - `**ucl(alpha=0.05)**` — Phase II UCL using the `**F_{p, m-p}**` distribution (**SciPy**). - `**is_out_of_control(x, *, alpha=0.05)`** — `**True`** if `**t2(x) > ucl(alpha=alpha)**` (`**alpha**` is keyword-only). --- ## Tests With `**[spc]**` installed: ```bash python3 -m pytest tests/test_spc.py -q ``` --- ## See also - `**README.md**` (full `**fiwicontrol**` package list and `**src/**` layout) - `**docs/install.md**` (optional `**[spc]**` alongside `**[flows]**`, `**[power]**`, …)