Coverage Report - us.daveread.utility.sixsigma.SigmaCalculator
 
Classes in this File Line Coverage Branch Coverage Complexity
SigmaCalculator
80%
41/51
100%
7/7
1.412
 
 1  
 package us.daveread.utility.sixsigma;
 2  
 
 3  
 import java.text.DecimalFormat;
 4  
 
 5  
 /**
 6  
  * <p>Title: SigmaCalculator
 7  
  * <p>Description: Calculate sigma given opportunities and defects
 8  
  * <p>Copyright: Copyright (c) 2005
 9  
  * <p>This program is free software; you can redistribute it and/or modify
 10  
  * it under the terms of the GNU General Public License as published by
 11  
  * the Free Software Foundation; either version 2 of the License, or
 12  
  * (at your option) any later version.
 13  
  * <p>This program is distributed in the hope that it will be useful,
 14  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  
  * GNU General Public License for more details.
 17  
  * <p>You should have received a copy of the GNU General Public License
 18  
  * along with this program; if not, write to the Free Software
 19  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 20  
  * </p>
 21  
  *
 22  
  *
 23  
  * <p>From: http://www.isixsigma.com/library/content/c020507a.asp
 24  
  * <p>Understanding The Formula
 25  
  * <br>Defects Per Million Opportunities (DPMO) = ((Total Defects) /
 26  
  *     (Total Opportunities)) * 1,000,000
 27  
  * <br>Defects (%) = ((Total Defects) / (Total Opportunities)) * 100
 28  
  * <br>Yield (%) = 100 - (Defects Percentage)
 29  
  * <br>process Sigma = NORMSINV(1-((Total Defects) / (Total Opportunities))) + 1.5
 30  
  *
 31  
  * <br><br>Alternatively,
 32  
  * <br>process Sigma = 0.8406 + SQRT(29.37 - 2.221 * (ln(DPMO))).
 33  
  * <br>Reference: Breyfogle, F., 1999. Implementing Six Sigma: Smarter
 34  
  * Solutions Using Statistical Methods. 2nd ed. John Wiley & Sons.
 35  
  *
 36  
  *
 37  
  * <p>Understanding The Basic And Advanced Modes
 38  
  * <p>The Basic Mode of the Sigma Calculator automatically adds a 1.5 Sigma
 39  
  * shift to the process Sigma value that is calculated. Why is this done?
 40  
  * It's done because it is the "standard" way that Sigma is reported
 41  
  * (note: this may be different in your company, but it is done in this
 42  
  * manner by Motorola, GE and many other companies). By doing so, the
 43  
  * calculator result assumes that you are providing long-term data and it is
 44  
  * providing short-term Sigma. The 1.5 Sigma shift is based on the assumption
 45  
  * that over time, and with a sufficiently large number of samples, a
 46  
  * realistic Sigma value is 1.5 Sigma less than that calculated to show the
 47  
  * success of your project (i.e. that shown in this calculator and in
 48  
  * reports to your company).
 49  
  *
 50  
  * <p>If you want to calculate the process Sigma using data other than
 51  
  * long-term, you should switch to the Advanced Mode where you can change
 52  
  * the process Sigma shift value from 1.5 to whatever you feel is appropriate.
 53  
  *
 54  
  * <p>Here are a couple of examples to help illustrate the calculations.
 55  
  * A long-term 93% yield (e.g. 100 opportunities, 7 defects) equates to a
 56  
  * process Sigma long-term value of 1.48 (with no Sigma shift) or a process
 57  
  * Sigma short-term value of 2.98 (with a 1.5 Sigma shift). A long-term 99.7%
 58  
  * yield (e.g. 1,000 opportunities, 3 defects) equates to a process Sigma
 59  
  * long-term value of 2.75 (with no Sigma shift) or a process Sigma short-term
 60  
  * value of 4.25 (with the 1.5 sigma shift).
 61  
  *
 62  
  * <p>Final Thought: When we talk about a Six Sigma process, we are referring
 63  
  * to the process short-term (now). When we talk about DPMO of the process,
 64  
  * we are referring to long-term (the future). We refer to 3.4 defects per
 65  
  * million opportunities as our goal. This means that we will have a 6 sigma
 66  
  * process now in order to have in the future (with the correction of 1.5)
 67  
  * a 4.5 sigma process -- which produces 3.4 defects per million opportunities.
 68  
  *
 69  
  * <p>Notice: Sigma with a capital "S" is used above to denote the process
 70  
  * Sigma, which is different than the typical statistical reference to
 71  
  * sigma with a small "s" which denotes the standard deviation.
 72  
  *
 73  
  * @author David Read
 74  
  * @version $Id: SigmaCalculator.java,v 1.3 2006/06/14 23:38:24 daveread Exp $
 75  
  */
 76  
 public class SigmaCalculator {
 77  
 
 78  
   /** Default sigma shift */
 79  
   private static final double SIGMASHIFT_DEFAULT = 0.0;
 80  
 
 81  
   /** The defined number of opportunities */
 82  
   private double opportunities;
 83  
 
 84  
   /** The defined number of defects */
 85  
   private double defects;
 86  
 
 87  
   /** The defined sigma shift */
 88  
   private double sigmaShift;
 89  
 
 90  
   /** The calculated DPMO */
 91  
   private double DPMO;
 92  
 
 93  
   /** The calculated DPO */
 94  
   private double DPO;
 95  
 
 96  
   /** The calculated defect percentage (100-based) */
 97  
   private double defectPercent;
 98  
 
 99  
   /** The calculated yield percentage (100-based) */
 100  
   private double yieldPercent;
 101  
 
 102  
   /** The calculated sigma - including any defined sigma shift */
 103  
   private double sigma;
 104  
 
 105  
   /**
 106  
    * Setup the calculator based on the supplied oppoerunities and defects.
 107  
    *
 108  
    * @param aOpportunities double The number of opportunities
 109  
    * @param aDefects double The number of defects
 110  
    */
 111  8
   public SigmaCalculator(double aOpportunities, double aDefects) {
 112  8
     setOpportunities(aOpportunities);
 113  8
     setDefects(aDefects);
 114  8
     sigmaShift = SIGMASHIFT_DEFAULT;
 115  8
   }
 116  
 
 117  
   /**
 118  
    * Calculates the values for the attributes such as DPMO, DPO, yield, and
 119  
    * sigma.
 120  
    *
 121  
    * This method should be called whenever the number of opportunities or
 122  
    * defects is updated.
 123  
    */
 124  
   private void calculate() {
 125  
 
 126  16
     if (opportunities != 0) {
 127  16
       DPO = defects / opportunities;
 128  
     }
 129  
     else {
 130  0
       DPO = 0.0;
 131  
     }
 132  
 
 133  16
     if (DPO < 0.0) {
 134  0
       DPO = 0.0;
 135  
     }
 136  16
     else if (DPO > 1.0) {
 137  0
       DPO = 1.0;
 138  
     }
 139  
 
 140  16
     DPMO = DPO * 1000000.0;
 141  16
     defectPercent = DPO * 100.0;
 142  16
     yieldPercent = 100.0 - defectPercent;
 143  
 
 144  
     // This simple formula can't handle high defect rates (e.g. > ~55/100)
 145  
     // sigma = 0.8406 + Math.sqrt(29.37 - 2.221 * Math.log(DPMO));
 146  
 
 147  16
     sigma = Math.sqrt(Math.log(1 / Math.pow(DPO, 2))) -
 148  
         ( (2.515517 + 0.802853 * (Math.sqrt(Math.log(1 / Math.pow(DPO, 2)))) +
 149  
            0.010328 * Math.pow( (Math.sqrt(Math.log(1 / Math.pow(DPO, 2)))), 2))) /
 150  
         ( (1 + 1.432788 * (Math.sqrt(Math.log(1 / Math.pow(DPO, 2)))) +
 151  
            0.189269 * Math.pow( (Math.sqrt(Math.log(1 / Math.pow(DPO, 2)))), 2) +
 152  
            0.001308 * Math.pow( (Math.sqrt(Math.log(1 / Math.pow(DPO, 2)))), 3)));
 153  
 
 154  
     // Adjust since formula above produces long term sigma (i.e. 4.5 at 3.4/1000000)
 155  16
     sigma += 1.5;
 156  
 
 157  16
     if (sigma > 6.0 || DPO <= 0.0) {
 158  8
       sigma = 6.0;
 159  
     }
 160  8
     else if (DPO >= 1.0) {
 161  0
       sigma = -3.5;
 162  
     }
 163  
 
 164  16
     sigma += getSigmaShift();
 165  16
   }
 166  
 
 167  
   /**
 168  
    * Sets the number of opportunities.  This will cause the calculator to update
 169  
    * the attributes such as DPMO, DPO, yield and sigma.
 170  
    *
 171  
    * @param aOpportunities double The number of opportunities
 172  
    */
 173  
   public void setOpportunities(double aOpportunities) {
 174  8
     opportunities = aOpportunities;
 175  8
     calculate();
 176  8
   }
 177  
 
 178  
   /**
 179  
    * Gets the number of opportunities.
 180  
    *
 181  
    * @return double The number of opportunities
 182  
    */
 183  
   public double getOpportunities() {
 184  0
     return opportunities;
 185  
   }
 186  
 
 187  
   /**
 188  
    * Sets the number of defects.  This will cause the calculator to update
 189  
    * the attributes such as DPMO, DPO, yield and sigma.
 190  
    *
 191  
    * @param aDefects double The number of defects
 192  
    */
 193  
   public void setDefects(double aDefects) {
 194  8
     defects = aDefects;
 195  8
     calculate();
 196  8
   }
 197  
 
 198  
   /**
 199  
    * Gets the number of defects.
 200  
    *
 201  
    * @return double The number of defects
 202  
    */
 203  
   public double getDefects() {
 204  0
     return defects;
 205  
   }
 206  
 
 207  
   /**
 208  
    * Sets the sigma shift amount.  Typically this is set to adjust for the
 209  
    * difference between shirt-term values and long-term expectations.
 210  
    * This will cause the calculator to update the sigma value.
 211  
    *
 212  
    * @param aSigmaShift double The sigma shift to be used
 213  
    */
 214  
   public void setSigmaShift(double aSigmaShift) {
 215  0
     sigmaShift = aSigmaShift;
 216  0
     calculate();
 217  0
   }
 218  
 
 219  
   /**
 220  
    * Gets the sigma shift amount.
 221  
    *
 222  
    * @return double The sigma shift to be used
 223  
    */
 224  
   public double getSigmaShift() {
 225  16
     return sigmaShift;
 226  
   }
 227  
 
 228  
   /**
 229  
    * Gets the sigma, with any sigma shift applied.
 230  
    *
 231  
    * @return double The sigma value
 232  
    */
 233  
   public double getSigma() {
 234  1
     return sigma;
 235  
   }
 236  
 
 237  
   /**
 238  
    * Gets the sigma as a formatted string, with the requested number of
 239  
    * decimal places.  Any sigma shift is applied.
 240  
    *
 241  
    * @param aSignificantDigits int The number of decimal places to output
 242  
    */
 243  
   public String getSigma(int aSignificantDigits) {
 244  1
     return formatNumber(aSignificantDigits, getSigma());
 245  
   }
 246  
 
 247  
   /**
 248  
    * Gets the DPMO (Defects Per Million Operations) value.
 249  
    *
 250  
    * @return double The DPMO
 251  
    */
 252  
   public double getDPMO() {
 253  2
     return DPMO;
 254  
   }
 255  
 
 256  
   /**
 257  
    * Gets the DPMO as a formatted string, with the requested number of
 258  
    * decimal places.
 259  
    *
 260  
    * @param aSignificantDigits int The number of decimal places to output
 261  
    */
 262  
   public String getDPMO(int aSignificantDigits) {
 263  2
     return formatNumber(aSignificantDigits, getDPMO());
 264  
   }
 265  
 
 266  
   /**
 267  
    * Gets the defect percentage (based on 100, not 1) i.e. 0.5 will be 50.0
 268  
    *
 269  
    * @return double The defect percentage
 270  
    */
 271  
   public double getDefectPercent() {
 272  1
     return defectPercent;
 273  
   }
 274  
 
 275  
   /**
 276  
    * Gets the defect percentage as a formatted string, with the requested number of
 277  
    * decimal places.
 278  
    *
 279  
    * @param aSignificantDigits int The number of decimal places to output
 280  
    */
 281  
   public String getDefectPercent(int aSignificantDigits) {
 282  1
     return formatNumber(aSignificantDigits, getDefectPercent());
 283  
   }
 284  
 
 285  
   /**
 286  
    * Gets the yield percentage (based on 100, not 1) i.e. 0.5 will be 50.0
 287  
    *
 288  
    * @return double The yield percentage
 289  
    */
 290  
   public double getYieldPercent() {
 291  1
     return yieldPercent;
 292  
   }
 293  
 
 294  
   /**
 295  
    * Gets the yield percentage as a formatted string, with the requested number of
 296  
    * decimal places.
 297  
    *
 298  
    * @param aSignificantDigits int The number of decimal places to output
 299  
    */
 300  
   public String getYieldPercent(int aSignificantDigits) {
 301  1
     return formatNumber(aSignificantDigits, getYieldPercent());
 302  
   }
 303  
 
 304  
   /**
 305  
    * Formats a value as a string, displaying a defined number of decimal
 306  
    * places.
 307  
    *
 308  
    * @param aSignificantDigits int The number of decimal places to output
 309  
    * @param value double The value to format
 310  
    *
 311  
    * @return String The formatted value
 312  
    */
 313  
   private String formatNumber(int aSignificantDigits, double value) {
 314  
     DecimalFormat format;
 315  
     String pattern, result;
 316  
 
 317  5
     pattern = "#,##0.";
 318  5
     for (int digits = 0; digits < aSignificantDigits; ++digits) {
 319  0
       pattern += "0";
 320  
     }
 321  5
     format = new DecimalFormat(pattern);
 322  
 
 323  5
     result = format.format(value);
 324  
 
 325  5
     if (result.endsWith(".")) {
 326  5
       result = result.substring(0, result.length() - 1);
 327  
     }
 328  
 
 329  5
     return result;
 330  
   }
 331  
 }