pub struct PChart { /* private fields */ }Expand description
Proportion nonconforming (P) chart.
Monitors the fraction of defective items in samples that may have different sizes. Control limits vary per subgroup when sample sizes differ.
§Formulas
- CL = p-bar = total_defectives / total_inspected
- UCL_i = p-bar + 3 * sqrt(p-bar * (1 - p-bar) / n_i)
- LCL_i = max(0, p-bar - 3 * sqrt(p-bar * (1 - p-bar) / n_i))
§Phase I and Phase II
PChart::new estimates p-bar from the samples it is given (Phase I).
To judge later samples against an established process, build the chart
with PChart::with_center: every limit then uses that p-bar with each
sample’s own n. Re-estimating from Phase I and Phase II samples together
would let a shift in Phase II pull the centre toward itself and widen its
own limits.
§Examples
use u_analytics::spc::PChart;
let mut chart = PChart::new();
chart.add_sample(3, 100).unwrap(); // 3 defectives out of 100
chart.add_sample(5, 100).unwrap();
chart.add_sample(2, 100).unwrap();
chart.add_sample(4, 100).unwrap();
let p_bar = chart.p_bar().expect("should have p_bar after adding samples");
assert!(p_bar > 0.0);§Reference
Montgomery, D.C. (2019). Introduction to Statistical Quality Control, 8th ed., Chapter 7, Section 7.3.
Implementations§
Source§impl PChart
impl PChart
Sourcepub fn with_center(p_bar: f64) -> Result<Self, ControlChartError>
pub fn with_center(p_bar: f64) -> Result<Self, ControlChartError>
Create a P chart whose centre line is a known p-bar, typically from a Phase I study (Phase II).
§Errors
ControlChartError::InvalidStandard unless p_bar is finite and
strictly between 0 and 1 — at 0 or 1 every limit collapses onto the
centre line.
Sourcepub fn add_sample(
&mut self,
defectives: u64,
sample_size: u64,
) -> Result<(), ControlChartError>
pub fn add_sample( &mut self, defectives: u64, sample_size: u64, ) -> Result<(), ControlChartError>
Add a sample with the number of defective items and the total sample size.
§Errors
ControlChartError::ZeroSampleSize
if sample_size is 0, or
ControlChartError::DefectivesExceedSampleSize
if defectives > sample_size. The chart is left unchanged; such a
sample used to be dropped silently, shifting every later point.
Sourcepub fn p_bar(&self) -> Option<f64>
pub fn p_bar(&self) -> Option<f64>
The centre line in use — the known p-bar for a chart built
with_center, otherwise the estimate — or None
if no data.
Sourcepub fn points(&self) -> &[AttributeChartPoint]
pub fn points(&self) -> &[AttributeChartPoint]
Get all chart points.
Sourcepub fn is_in_control(&self) -> bool
pub fn is_in_control(&self) -> bool
Check if the process is in statistical control.