PDA

View Full Version : Product for Cp / Cpk calculation

Sancha
01-15-2010, 03:46 AM
Hello !

I need a statistic library to calculate process capability (Cp and Cpk).
Can you please help me to find it ? Maybe a IMSL Numerical Libraries can do that ?

Sorry for my English, it's a little bad...

Anycase, thank you.

Sancha
01-15-2010, 05:47 AM
No one can help me ? :(

ed
01-15-2010, 06:25 AM
Actually I wrote something for Capability statistics quite some time ago for a prospect. All of the values are pretty straightforward to compute. Below is my Java code in a sample program. The main bit of course is the computeCp() method. This code uses the JMSL Library for computing summary statistics, but it isn't integral to the calculations.

There are also two ways to compute Cpk; both are here, but one is commented out.

import com.imsl.stat.Summary;
import com.imsl.math.*;

public class Capability {
/*
* Data: The sample consists of n=100 observations on the bursting strength
* of glass bottles. Source: Chapter 9 of
* Introduction to Statistical Quality Control by Douglas C. Montgomery.
*
* Capability statistics results for this data can be found on
* http://www.sgcorp.com/process_capability_analysis.htm
* http://www.isixsigma.com/library/content/c010806a.asp
*
* and http://en.wikipedia.org/wiki/Process_performance_index
*/

private static final double x[] = {
265.0,197.0,346.0,280.0,265.0,200.0,
221.0,265.0,261.0,278.0,205.0,286.0,
317.0,242.0,254.0,235.0,176.0,262.0,
248.0,250.0,263.0,274.0,242.0,260.0,
281.0,246.0,248.0,271.0,260.0,265.0,
307.0,243.0,258.0,321.0,294.0,328.0,
263.0,245.0,274.0,270.0,220.0,231.0,
276.0,228.0,223.0,296.0,231.0,301.0,
337.0,298.0,268.0,267.0,300.0,250.0,
260.0,276.0,334.0,280.0,250.0,257.0,
260.0,281.0,208.0,299.0,308.0,264.0,
280.0,274.0,278.0,210.0,234.0,265.0,
187.0,258.0,235.0,269.0,265.0,253.0,
254.0,280.0,299.0,214.0,264.0,267.0,
283.0,235.0,272.0,287.0,274.0,269.0,
215.0,318.0,271.0,293.0,277.0,290.0,
283.0,258.0,275.0,251.0};
/* Lower Specification Limit. */
private static final double lsl = 200.;
/* Target Specification Limit. */
private static final double target = 250.;
/* Upper Specification Limit. */
private static final double usl = 300.;

/* Compute an alternative sigma */
private static double computeSigma2(double[] x, double target) {
int nobs = x.length;
double s2 = 0.0;
for (int i=0;i<nobs;i++) {
s2 += (x[i]-target)*(x[i]-target);
}
s2 = JMath.sqrt(s2/(nobs-1));
return s2;
}

/* Compute the Capability Statistics */
private static double[] computeCp(double lsl, double target, double usl,
double mean, double sigma, double sigma2) {
double[] cp = new double[6];
/* Compute C_p. = (usl-lsl)/(6*stdev) */
cp[0] = (usl-lsl)/(6.*sigma);
/* Compute C_pl = (mean-lsl)/(3*stdev). */
cp[1] = (mean-lsl)/(3.*sigma);
/* Compute C_pu = (mean-lsl)/(3*stdev). */
cp[2] = (usl-mean)/(3.*sigma);
/* Compute K = ABS(((usl+lsl)/2)-mean)/(.5*(usl-lsl)). */
cp[3] = JMath.abs(((usl+lsl)/2.0)-mean)/(0.5*(usl-lsl));
/* Compute C_pk = (1-k)*C_p. <-- 'old' method */
//cp[4] = (1-cp[3])*cp[0];
/* Compute C_pk = min(Cpl, Cpu) */
cp[4] = Math.min(cp[1], cp[2]);
/* Compute C_pm */
cp[5] = (usl-lsl)/(6.*sigma2);
return cp;
}

public static void main(String[] args) {

Summary summary = new Summary();
summary.update(x);

double mean = summary.getMean();
double sigma = summary.getSampleStandardDeviation();
double sigma2 = computeSigma2(x, target);
double[] cpstats = computeCp(lsl, target, usl, mean, sigma, sigma2);

/*
System.out.println("Mean is "+mean);
System.out.println(" ");
System.out.println("Sigma is "+sigma);
System.out.println(" ");
System.out.println("Sigma2 is "+sigma2);
System.out.println(" ");
*/

PrintMatrix p = new PrintMatrix("* * * Capability Statistics * * *");
PrintMatrixFormat mf = new PrintMatrixFormat();
String[] labels = {"C_p","C_pl","C_pu","k","C_pk","C_pm"};
/* not sure how to get the labels in the matrix too */
p.print(mf, cpstats);

System.out.println("C_p is "+cpstats[0]);
System.out.println("C_pl is "+cpstats[1]);
System.out.println("C_pu is "+cpstats[2]);
System.out.println("k is "+cpstats[3]);
System.out.println("C_pk is "+cpstats[4]);
System.out.println("C_pm is "+cpstats[5]);

}
}

Sancha
01-15-2010, 06:53 AM
Thank you very much for this code ! It's very kind !

So, the IMSL Numeric Library don't permit me to calculate Cp and Cpk ?

ed
01-15-2010, 07:37 AM
No, the library doesn't include these calculations.