| name | process-capability-calculator |
| description | Process capability analysis skill with Cp, Cpk, Pp, Ppk calculations and specification compliance assessment. |
| allowed-tools | Bash(*) Read Write Edit Glob Grep WebFetch |
| metadata | {"author":"babysitter-sdk","version":"1.0.0","category":"quality-engineering","backlog-id":"SK-IE-015"} |
| graph | {"domains":["domain:industrial-engineering"],"skillAreas":["skill-area:statistical-analysis","skill-area:organizational-design","skill-area:data-analysis"],"roles":["role:operations-analyst","role:research-engineer"]} |
process-capability-calculator
You are process-capability-calculator - a specialized skill for analyzing process capability with respect to specifications.
Overview
This skill enables AI-powered capability analysis including:
- Capability index calculation (Cp, Cpk)
- Performance index calculation (Pp, Ppk)
- Specification limit analysis
- Normality testing (Shapiro-Wilk, Anderson-Darling)
- Non-normal capability analysis (Box-Cox transformation)
- PPM defect rate estimation
- Capability histogram with distribution overlay
- Six Sigma level calculation
Prerequisites
- Python 3.8+ with numpy, scipy, statsmodels
- Process measurement data
- Specification limits (USL, LSL)
Capabilities
1. Capability Index Calculation (Cp, Cpk)
import numpy as np
from scipy import stats
def calculate_capability_indices(data, usl, lsl, subgroup_size=None):
"""
Calculate Cp, Cpk capability indices
Uses within-subgroup variation (R-bar/d2 or S-bar/c4)
Requires stable process
"""
x = np.array(data)
x_bar = np.mean(x)
specification_width = usl - lsl
if subgroup_size and subgroup_size > 1:
d2 = {2: 1.128, 3: 1.693, 4: 2.059, 5: 2.326}
sigma_within = np.std(x, ddof=1)
else:
mr = np.abs(np.diff(x))
mr_bar = np.mean(mr)
sigma_within = mr_bar / 1.128
cp = specification_width / (6 * sigma_within)
cpu = (usl - x_bar) / (3 * sigma_within)
cpl = (x_bar - lsl) / (3 * sigma_within)
cpk = min(cpu, cpl)
return {
"Cp": round(cp, 3),
"Cpk": (cpk, ),
: (cpu, ),
: (cpl, ),
: (sigma_within, ),
: (x_bar, ),
: usl,
: lsl,
: interpret_capability(cpk)
}
():
cpk >= :
cpk >= :
cpk >= :
cpk >= :
cpk >= :
:
2. Performance Index Calculation (Pp, Ppk)
def calculate_performance_indices(data, usl, lsl):
"""
Calculate Pp, Ppk performance indices
Uses overall variation (long-term)
Does not require stable process
"""
x = np.array(data)
x_bar = np.mean(x)
sigma_overall = np.std(x, ddof=1)
specification_width = usl - lsl
pp = specification_width / (6 * sigma_overall)
ppu = (usl - x_bar) / (3 * sigma_overall)
ppl = (x_bar - lsl) / (3 * sigma_overall)
ppk = min(ppu, ppl)
return {
"Pp": round(pp, 3),
"Ppk": round(ppk, 3),
"Ppu": round(ppu, 3),
"Ppl": round(ppl, 3),
"sigma_overall": round(sigma_overall, 4),
"process_mean": round(x_bar, 4),
"interpretation": interpret_capability(ppk)
}
3. Normality Testing
def test_normality(data):
"""
Test data for normality using multiple tests
"""
x = np.array(data)
n = len(x)
results = {}
if n <= 5000:
stat, p_value = stats.shapiro(x)
results["shapiro_wilk"] = {
"statistic": round(stat, 4),
"p_value": round(p_value, 4),
"conclusion": "Normal" if p_value > 0.05 else "Non-normal"
}
ad_result = stats.anderson(x, dist='norm')
results["anderson_darling"] = {
"statistic": round(ad_result.statistic, 4),
"critical_values": dict(zip(
['15%', '10%', '5%', '2.5%', '1%'],
[round(cv, 4) for cv in ad_result.critical_values]
)),
"conclusion": "Normal" if ad_result.statistic < ad_result.critical_values[2] else "Non-normal"
}
if n >= :
stat, p_value = stats.normaltest(x)
results[] = {
: (stat, ),
: (p_value, ),
: p_value >
}
normal_count = ( r results.values() r.get() == )
results[] = normal_count >=
results[] = {
: (stats.skew(x), ),
: (stats.kurtosis(x), ),
: n
}
results
4. Non-Normal Capability Analysis
from scipy.stats import boxcox
from scipy.optimize import brentq
def nonnormal_capability(data, usl, lsl, method='percentile'):
"""
Calculate capability for non-normal data
Methods:
- percentile: Use empirical percentiles
- boxcox: Transform to normal using Box-Cox
- weibull: Fit Weibull distribution
"""
x = np.array(data)
if method == 'percentile':
p0135 = np.percentile(x, 0.135)
p99865 = np.percentile(x, 99.865)
median = np.median(x)
spread = p99865 - p0135
cp_equiv = (usl - lsl) / spread if spread > 0 else np.inf
cpu_equiv = (usl - median) / ((p99865 - median) * 2) if (p99865 - median) > 0 else np.inf
cpl_equiv = (median - lsl) / ((median - p0135) * 2) if (median - p0135) > 0 else np.inf
cpk_equiv = min(cpu_equiv, cpl_equiv)
return {
"method": "percentile",
"Cp_equivalent": round(cp_equiv, 3),
"Cpk_equivalent": round(cpk_equiv, 3),
"p0135": round(p0135, 4),
: (p99865, ),
: (median, )
}
method == :
shift =
np.(x) <= :
shift = (np.(x)) +
x_shifted = x + shift
:
x_shifted = x
transformed, lambda_opt = boxcox(x_shifted)
lambda_opt == :
usl_t = np.log(usl + shift)
lsl_t = np.log(lsl + shift)
:
usl_t = ((usl + shift)**lambda_opt - ) / lambda_opt
lsl_t = ((lsl + shift)**lambda_opt - ) / lambda_opt
result = calculate_capability_indices(transformed, usl_t, lsl_t)
result[] =
result[] = (lambda_opt, )
result[] = shift
result
5. PPM and Sigma Level Calculation
def calculate_ppm_sigma(cpk, process_centered=True):
"""
Calculate expected PPM defect rate and sigma level
"""
if process_centered:
z = 3 * cpk
ppm_total = 2 * (1 - stats.norm.cdf(z)) * 1e6
ppm_upper = ppm_total / 2
ppm_lower = ppm_total / 2
else:
z = 3 * cpk
ppm_worst = (1 - stats.norm.cdf(z)) * 1e6
ppm_total = ppm_worst
sigma_short_term = 3 * cpk
sigma_long_term = sigma_short_term + 1.5
return {
"ppm_total": round(ppm_total, 1),
"ppm_percent": round(ppm_total / 1e4, 4),
"sigma_short_term": round(sigma_short_term, 2),
"sigma_long_term": round(sigma_long_term, 2),
"yield_percent": round((1 - ppm_total / 1e6) * 100, 4),
"dpmo": round(ppm_total, 0)
}
SIGMA_REFERENCE = {
: {: , : , : },
: {: , : , : },
: {: , : , : },
: {: , : , : },
: {: , : , : },
: {: , : , : }
}
6. Capability Report Generation
def generate_capability_report(data, usl, lsl, target=None):
"""
Generate comprehensive capability analysis report
"""
x = np.array(data)
report = {
"summary": {
"n": len(x),
"usl": usl,
"lsl": lsl,
"target": target or (usl + lsl) / 2,
"specification_width": usl - lsl
},
"descriptive_statistics": {
"mean": round(np.mean(x), 4),
"std": round(np.std(x, ddof=1), 4),
"min": round(np.min(x), 4),
"max": round(np.max(x), 4),
"range": round(np.ptp(x), 4),
"median": round(np.median(x), 4)
}
}
normality = test_normality(x)
report["normality_test"] = normality
if normality["overall_assessment"] == "Normal":
report["capability_indices"] = calculate_capability_indices(x, usl, lsl)
report["performance_indices"] = calculate_performance_indices(x, usl, lsl)
report["analysis_method"] =
:
report[] = nonnormal_capability(x, usl, lsl, method=)
report[] = nonnormal_capability(x, usl, lsl, method=)
report[] =
cpk = report[].get() report[].get(, )
report[] = calculate_ppm_sigma(cpk)
out_of_spec_high = np.(x > usl)
out_of_spec_low = np.(x < lsl)
report[] = {
: (out_of_spec_high),
: (out_of_spec_low),
: (out_of_spec_high + out_of_spec_low),
: ((out_of_spec_high + out_of_spec_low) / (x) * , )
}
report[] = generate_recommendations(report)
report
():
cpk = report[].get() report[].get(, )
recommendations = []
cpk < :
recommendations.append()
recommendations.append()
cpk < :
recommendations.append()
cpk < :
recommendations.append()
:
recommendations.append()
mean = report[][]
target = report[][]
(mean - target) > (report[][] * ):
recommendations.append()
recommendations
Process Integration
This skill integrates with the following processes:
statistical-process-control-implementation.js
design-of-experiments-execution.js
root-cause-analysis-investigation.js
Output Format
{
"summary": {
"n": 150,
"usl": 10.5,
"lsl": 9.5
},
"capability_indices": {
"Cp": 1.45,
"Cpk": 1.32,
"interpretation": "Good (4 sigma)"
},
"defect_prediction": {
"ppm_total": 966,
"sigma_long_term": 4.5,
"yield_percent": 99.903
},
"recommendations": [
"Process capable - maintain monitoring",
"Consider centering adjustment"
]
}
Best Practices
- Ensure stability first - Capability analysis requires stable process
- Test normality - Use appropriate methods for non-normal data
- Sufficient sample size - Minimum 100 observations recommended
- Use Cpk not just Cp - Centering matters
- Report both Cp/Cpk and Pp/Ppk - Show short and long-term capability
- Include confidence intervals - Single point estimates can be misleading
Constraints
- Process must be in statistical control
- Document all specification limits
- Note any data transformations
- Report normality test results