Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Component Inferential Statistics (Confidence Intervals & Hypothesis Testing)

An inferential statistics pipeline applied to repeated electronic component measurements, built to assess spec compliance with statistical confidence rather than raw pass/fail thresholds.

This project illustrates a typical quality-control / metrology use case: quantifying measurement uncertainty and testing compliance against a specification, based on repeated observations of the same components.

Goal

Given repeated measurements of an electrical characteristic (e.g. resistance, output voltage) across a batch of components, the pipeline aims to:

  • estimate the true mean value with a 95% confidence interval,
  • check whether the underlying distribution is compatible with a normal assumption (Shapiro-Wilk),
  • test whether the measured mean is statistically different from a target/nominal spec value (one-sample t-test),
  • determine whether the component is within its tolerance band with statistical confidence, not just on a single reading,
  • summarise measurement dispersion per individual unit (repeated-measures view).

Tech stack

  • Python 3
  • NumPy — numerical computation
  • SciPy (scipy.stats) — confidence intervals, Shapiro-Wilk test, one-sample t-test
  • Pandas — data handling
  • Matplotlib — visualisation

Project structure

component-inferential-stats/
├── src/
│   ├── generate_data.py     # synthetic dataset generator (replace with real data)
│   └── analyze.py           # full inferential statistics pipeline
├── data/
│   ├── measurements.csv     # raw measurements (unit_id, repeat, value)
│   └── unit_summary.csv     # per-unit mean/std/CI summary (generated)
├── images/
│   └── analysis_summary.png # generated plots
└── README.md

How it works

  1. src/generate_data.py — generates a synthetic batch of repeated measurements (30 units x 5 repeats) with realistic unit-to-unit and measurement noise. Replace data/measurements.csv with your own real measurement file — the analysis script only expects three columns: unit_id, repeat, value.

  2. src/analyze.py — the analysis pipeline:

    • confidence_interval() — computes a Student's t-based confidence interval (used instead of a z-interval because the population standard deviation is unknown and estimated from a finite sample).
    • Shapiro-Wilk normality test to check whether the t-based approach is justified.
    • One-sample t-test (scipy.stats.ttest_1samp) against the target/spec value.
    • Spec-compliance check: is the confidence interval fully inside the tolerance band, and what proportion of individual measurements fall outside it.
    • Per-unit repeated-measures summary: mean, standard deviation and CI margin computed separately for each unit, exported to data/unit_summary.csv.
    • Two plots: overall distribution with CI/spec/target overlaid, and per-unit means with error bars.

Usage

pip install numpy scipy pandas matplotlib

# 1. Generate (or replace with your own) measurement data
python src/generate_data.py

# 2. Run the full analysis
python src/analyze.py

Results on the generated dataset

On a synthetic batch of 150 measurements (30 units, 5 repeats each, target = 100.0, spec = [98.0, 102.0]):

  • Sample mean: 99.94, standard deviation: 1.33
  • Shapiro-Wilk: distribution compatible with normality (p = 0.30)
  • 95% confidence interval: [99.73, 100.16] — fully inside the spec band
  • One-sample t-test vs target: p = 0.61 → no statistically significant deviation from target
  • 15.3% of individual readings fall outside spec, despite the batch mean being compliant — illustrating why compliance should be assessed on the estimated population mean (with its uncertainty), not on isolated readings

Limitations & possible improvements

  • Assumes independent measurements within a unit; a mixed-effects model (unit as random effect) would better handle the repeated-measures structure than treating all 150 readings as i.i.d.
  • Single population tested; extending to a two-sample or ANOVA design would allow comparing several batches/production lines.
  • Could add a Bayesian estimation of the mean (posterior credible interval) as an alternative to the frequentist confidence interval, particularly relevant for small sample sizes or when prior information from previous batches is available.

About

An inferential statistics pipeline applied to repeated electronic component measurements, built to assess spec compliance with statistical confidence rather than raw pass/fail thresholds.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages