pub struct XBarRChart { /* private fields */ }Expand description
X-bar and Range (X-bar-R) control chart.
Monitors the process mean (X-bar chart) and process variability (R chart)
using subgroup ranges. Accepts subgroup sizes
MIN_SUBGROUP_SIZE..=MAX_SUBGROUP_SIZE; above about n = 10 the range
discards enough of each subgroup’s information that XBarSChart is the
usual choice.
§Algorithm
- For each subgroup, compute the mean (X-bar) and range (R).
- Compute the grand mean (X-double-bar) and average range (R-bar).
- X-bar chart limits: CL = X-double-bar, UCL/LCL = CL +/- A2 * R-bar.
- R chart limits: CL = R-bar, UCL = D4 * R-bar, LCL = D3 * R-bar.
§Examples
use u_analytics::spc::{XBarRChart, ControlChart};
let mut chart = XBarRChart::new(5).expect("subgroup size is in range");
chart.add_sample(&[25.0, 26.0, 24.5, 25.5, 25.0]).unwrap();
chart.add_sample(&[25.2, 24.8, 25.1, 24.9, 25.3]).unwrap();
chart.add_sample(&[25.1, 25.0, 24.7, 25.3, 24.9]).unwrap();
let limits = chart.control_limits().expect("should have limits after 3 samples");
assert!(limits.ucl > limits.cl);
assert!(limits.cl > limits.lcl);§Reference
Montgomery, D.C. (2019). Introduction to Statistical Quality Control, 8th ed., Chapter 6: Control Charts for Variables.
Implementations§
Source§impl XBarRChart
impl XBarRChart
Sourcepub fn with_rules(self, rules: RuleSet) -> Self
pub fn with_rules(self, rules: RuleSet) -> Self
Apply only the given run tests when computing limits.
Defaults to RuleSet::shewhart – the 3-sigma test alone; the
supplementary tests raise the false alarm rate and are asked for here.
Existing points are re-evaluated, so the call may be made at any time.
§Examples
use u_analytics::spc::{XBarRChart, ControlChart, RuleSet, ViolationType};
let chart = XBarRChart::new(5).expect("5 is within range")
.with_rules(RuleSet::nelson().without(ViolationType::FourteenAlternating));Sourcepub fn new(subgroup_size: usize) -> Result<Self, ControlChartError>
pub fn new(subgroup_size: usize) -> Result<Self, ControlChartError>
Create a new X-bar-R chart with the given subgroup size.
§Errors
Returns ControlChartError::SubgroupSizeOutOfRange when
subgroup_size is outside MIN_SUBGROUP_SIZE..=MAX_SUBGROUP_SIZE.
The size is data in most callers – it comes from the measurements a
user supplied – so rejecting it is an ordinary outcome rather than a
contract violation, and a boundary that cannot unwind (WebAssembly, C)
needs it as a value.
Sourcepub fn sigma_hat(&self) -> Option<f64>
pub fn sigma_hat(&self) -> Option<f64>
Short-term (within-subgroup) sigma estimated from this chart:
sigma-hat = R-bar / d2(n).
This is the quantity a capability study needs for Cp/Cpk, and it cannot
be recovered from a flat measurement vector — it depends on the subgroup
structure the chart already holds. Returning it here is what lets a
caller feed crate::capability::ProcessCapability::compute without
reimplementing the d2 table.
Returns None if there is not enough data for control limits.
§Examples
use u_analytics::spc::{ControlChart, XBarRChart};
let mut chart = XBarRChart::new(5).expect("subgroup size is in range");
for g in [[9.9, 10.1, 10.0, 9.8, 10.2], [10.3, 9.7, 10.0, 10.1, 9.9]] {
chart.add_sample(&g).unwrap();
}
let sigma = chart.sigma_hat().expect("limits available");
assert!(sigma > 0.0);Sourcepub fn sigma_hat_df(&self) -> Option<f64>
pub fn sigma_hat_df(&self) -> Option<f64>
Degrees of freedom of sigma_hat – what
CapabilityIndices::intervals
takes as within_df for Cp/Cpk intervals.
R-bar of m subgroups of n has squared coefficient of variation
(d3/d2)^2 / m; David’s (1951) approximation turns it into the degrees
of freedom of a sample standard deviation with the same precision –
fewer than the m (n - 1) a pooled standard deviation would have, the
price of using the range. d3/d2 is (D4 - 1) / 3.
Returns None if there is not enough data for control limits.
§Examples
use u_analytics::spc::{ControlChart, XBarRChart};
let mut chart = XBarRChart::new(5).expect("subgroup size is in range");
for g in [[9.9, 10.1, 10.0, 9.8, 10.2], [10.3, 9.7, 10.0, 10.1, 9.9]] {
chart.add_sample(&g).unwrap();
}
let df = chart.sigma_hat_df().expect("limits available");
assert!(df > 7.0 && df < 8.0); // two ranges of five: fewer than 2 x 4Sourcepub fn r_limits(&self) -> Option<ControlLimits>
pub fn r_limits(&self) -> Option<ControlLimits>
Get the R chart control limits, or None if insufficient data.
Sourcepub fn r_points(&self) -> &[ChartPoint]
pub fn r_points(&self) -> &[ChartPoint]
Get the R chart points.
Trait Implementations§
Source§impl Clone for XBarRChart
impl Clone for XBarRChart
Source§impl ControlChart for XBarRChart
impl ControlChart for XBarRChart
Source§fn add_sample(&mut self, sample: &[f64]) -> Result<(), ControlChartError>
fn add_sample(&mut self, sample: &[f64]) -> Result<(), ControlChartError>
Add a subgroup sample. The sample length must equal the chart’s subgroup size.
Source§fn control_limits(&self) -> Option<ControlLimits>
fn control_limits(&self) -> Option<ControlLimits>
None if insufficient data.