macro ciforp badcount inspectd; output pi upperCI lowerCI. #Accepts D and n info and calculates and plots running 95% CI for p. #Column badcount should contain the number of defectives (D) found #in the samples of size indicated in inspectd (n). The CI limits for #the cumulative observations are calculated using a chisquare #approximation. No check is made to determine if the samples are #sufficiently large to justify the use of the approximation. #Example call: # mtb> %ciforp 'di' 'n'; # subc> output c3-c5. #By PGMathews 1 Oct 2001 V1.0 #Rev: 1/26/02 (PGM): Changed to two sided interval with run chart. #Rev: 11/28/04 (PGM): Moved pi and UCI/LCI to subcommand. #Mathews and Malnar, Statistical Trainers and Consultants #217 Third Street, Fairport Harbor, OH 44077 #440-350-0911 pmathews@apk.net mcolumn badcount inspectd pi upperCI lowerCI mcolumn cumbad cuminsp run fractbad mconstant howmany i df ucritval lcritval note note Macro is running ... note brief 0 let pi=badcount/inspectd #Find the sample fraction defective call runningsum badcount cumbad #running sum of defectives call runningsum inspectd cuminsp #running sum of units inspected let fractbad=cumbad/cuminsp #running fraction defective count badcount howmany #totals do i=1:howmany let df=2*(cumbad(i)+1) invcdf 0.975 ucritval; #upper limit for p chisquare df. let upperCI(i)=ucritval/2/cuminsp(i) invcdf 0.025 lcritval; #lower limit for p chisquare df. let lowerCI(i)=lcritval/2/cuminsp(i) enddo set run 1:howmany end plot pi*run fractbad*run upperCI*run lowerCI*run; symbol; type 1 0 0 0; size 0.5 1 1 1; connect; type 1 1 1 1; size 1 2 1 1; color 14 1 1 1; minimum 2 0; axis 1; label "Run"; axis 2; label "Fraction Defective"; footnote "Mathews and Malnar, October 2001"; size 0.7; title "95% CI for Cumulative Fraction Defective"; overlay. brief endmacro ############################################################################## macro runningsum cin cout #finds running cumulative sum of cin and puts result in cout #by PGMathews 1 Oct 2001 v1.0 #Mathews and Malnar, Statistical Trainers and Consultants #217 Third Street, Fairport Harbor, OH 44077 #440-350-0911 pmathews@apk.net #Example call: # mtb > %runningsum c1 c2 mcolumn cin cout mconstant howmany i count cin howmany let cout(1)=cin(1) do i=2:howmany let cout(i)=cout(i-1)+cin(i) enddo endmacro