Showing posts with label area under a curve. Show all posts
Showing posts with label area under a curve. Show all posts

Monday, August 10, 2009

Visualizing Sigma: A JMP JSL Demostration (reposted from http://elsmar.com/Forums/blog.php?b=135)

This is a repost from: http://elsmar.com/Forums/blog.php?b=135
Hope it would help someone out there.

In the elmar's cove forum, i have written this note:




This is again for the JMP users out there.

Lately I have been noticing that whenever I am conducting trainings, it helps when the participants have a way to visualize the concepts that are being presented to them. In a recent example I was asked what is the basis of the value 6 in the Pp formula (USL-LSL)/(6*StdDev). Here is JMP JSL script that illustrates the logic behind the value 6.

A sample window is shown below. It is interactive. After showing this, you may then explain that the sigma is equivalent to distance from the center to the point of inflection on a normal curve,and you can fit about 6 of this length from one end of the curve to the other end. The output window is like this:

Note: You can freely use and share this script. I would be grateful though if you would give credit to me and point to this forum as the source.

Regards,
Reynald Francisco





The JMP output window is shown below:







The JMP JSL Scripth5>



Clear Globals();







/*Define constants*/

rsqrt2pi = 1 / Sqrt( 2 * Pi() );

e = e();

/*Define intial average

Define initial Sigma within

Get user information through a dialog box*/



dlg = Dialog(

"VISUALIZING SIGMA: A DEMOSTRATION",

" ",

"Enter the following information to begin, then click on OK",

" ",

V List(

V List(

" Population parameter:",

"",

Line Up( 2,

" Mean", mu = Edit Number( 0 ),

" Standard Deviation", sigma = Edit Number( 1 )

),

"",



)

),



" ",

H List( Button( "OK" ), Button( "Cancel" ) )

);





If( dlg["Button"] == -1,

Throw( "User cancelled" )

);

Remove From( dlg );

Eval List( dlg );





/*Define the output window*/

OUT_WINDOW = New Window( "VISUALIZING SIGMA: A JMP JSL DEMOSTRATION",

Border Box(

TOP( 5 ),

Left( 5 ),

Panel Box( "VISUALIZING SIGMA",

V List Box(

T1 = Text Box( "Move the slider below to adjust the Sigma." ),

T2 = Text Box( "Move the handle of the curve to adjust the Mean" ),

NormCurve = Graph Box(

FrameSize( 500, 350 ),

Y Scale( 0, 1.40 * rsqrt2pi / sigma ),

X Scale( mu - 10 * sigma, mu + 10 * sigma ),

Double Buffer,

Pen Color( "red" );

Text Color( "red" );

Text( {mu + 1 * sigma, rsqrt2pi / sigma * e ^ (-1 / 2)}, "Sigma = ", sigma );

LINEMATRIX_X = {mu, mu + sigma};

LINEMATRIX_X = Matrix( LINEMATRIX_X );

LINEMATRIX_Y = {rsqrt2pi / sigma * e ^ (-1 / 2), rsqrt2pi / sigma * e ^ (-1 / 2

)};

LINEMATRIX_Y = Matrix( LINEMATRIX_Y );

Arrow( LINEMATRIX_X, LINEMATRIX_Y );

LINEMATRIX_X1 = {mu + sigma, mu};

LINEMATRIX_X1 = Matrix( LINEMATRIX_X1 );

LINEMATRIX_Y1 = {rsqrt2pi / sigma * e ^ (-1 / 2), rsqrt2pi / sigma * e ^ (-1 /

2)};

LINEMATRIX_Y1 = Matrix( LINEMATRIX_Y1 );

Arrow( LINEMATRIX_X1, LINEMATRIX_Y1 );

Pen Color( "blue" );

Text Color( "blue" );

Pen Size( 2 );

Text Color( "BLUE" );

Text( {mu, rsqrt2pi / sigma}, "----->Mean = ", Char( Round( mu, 3 ) ) );

Y Function( Normal Density( (x - mu) / sigma ) / sigma, x );

Pen Size( 1 );

Pen Color( "Green" );

V Line( mu, 0, rsqrt2pi / sigma );

Line Style( 2 );

/*V Line( mu + sigma, 0, rsqrt2pi / sigma * e ^ (-1 / 2) );*/

V Line( mu + 2 * sigma, 0, rsqrt2pi / sigma * e ^ (-4 / 2) );

V Line( mu + 3 * sigma, 0, rsqrt2pi / sigma * e ^ (-9 / 2) );

V Line( mu - sigma, 0, rsqrt2pi / sigma * e ^ (-1 / 2) );

V Line( mu - 2 * sigma, 0, rsqrt2pi / sigma * e ^ (-4 / 2) );

V Line( mu - 3 * sigma, 0, rsqrt2pi / sigma * e ^ (-9 / 2) );

Pen Color( "Red" );

ARROW_MAT_X = {mu + sigma, mu + sigma};

ARROW_MAT_Y = {rsqrt2pi / sigma * e ^ (-1 / 2), 0};

ARROW_MAT_X = Matrix( ARROW_MAT_X );

ARROW_MAT_Y = Matrix( ARROW_MAT_Y );

Arrow( ARROW_MAT_X, ARROW_MAT_Y );

Handle( mu, rsqrt2pi / sigma, mu = x );

),





H List Box(

Text Color( "BLUE" );

T3 = Text Box( "SIGMA VALUE" );,

SB1 = Slider Box( 0.5 * sigma, 10 * sigma, sigma, NormCurve <<>









Thursday, August 6, 2009

Cp vs Cpk: Illustrating the Impact of Mean Shift and Sigma Changes

This is a script I developed to help me in explaining the concepts of Cp/Pp and Cpk/Ppk whenever I am conducting Six Sigma trainings. This is one of the reasons I appreciate JMP's JSL. It allows me to customize demostrations for my trainees that visually aid them in grasping Six Sigma concepts.
You may freely use. I would be grateful if you would give the credit to me and refer to this blog.

Reynald Francisco
http://statisticalprocesscontrols.blogspot.com/



The JMP JSL Script




dlg = Dialog(
V List(V List("Cpk Parameters","",
Line Up(2,
"Mean", mu = Edit Number(0),
"Standard Deviation", sigma = Edit Number(1)
),"","",
"Define Specifications","",
Line Up( 2,
"USL ",USL = Edit Number(2)
),Line Up( 2,
"LSL ",LSL = Edit Number(-2)
)
),
H List( Button("OK"), Button("Cancel") )
));


If( dlg["Button"] == -1, Throw( "User cancelled" ) );
Remove From( dlg ); Eval List( dlg );






rsqrt2pi = 1/sqrt(2*pi());

New Window("Cpk Demostration",

Graph Box(
FrameSize(500,500),
XScale(mu-8*sigma,mu+8*sigma),
yScale(0,1.40*rsqrt2pi/sigma),
Double Buffer,
Pencolor("blue"),
pensize(1),
text size(12),
TextColor("black"),
YFunction(Normal Density((x-mu)/sigma)/sigma, x); /*Y-scale is Normalized to Z-scores*/
YFunction(Normal Density((x-mu)/sigma)/sigma, x,fill(20),max(LSL)); /*Fill low*/
YFunction(Normal Density((x-mu)/sigma)/sigma, x,fill(20),min(USL)); /*Fill high*/
Handle(mu,rsqrt2pi/sigma,mu=x;sigma=rsqrt2pi/y);
Pencolor("red"),
pensize(1),
text size(10),
TextColor("black"),
XFunction(LSL, y);
Handle(LSL,0.45*rsqrt2pi/sigma,LSL=x);
XFunction(USL, y);
Handle(USL,0.55*rsqrt2pi/sigma,USL=x);
text({mu,0.85*rsqrt2pi/sigma},"mu ",mu," sigma ",sigma);
textcolor("red");
text({LSL,0.45*rsqrt2pi/sigma},"LSL= ",LSL);
text({USL,0.55*rsqrt2pi/sigma},"USL= ",USL);
Pencolor("blue"),
pensize(1),
text size(11),
TextColor("blue"),
Cpu=(USL-mu)/(3*sigma);
Zu=(USL-mu)/sigma;
Zl=(LSL-mu)/sigma;
yield=normal distribution(Zu)- normal distribution(Zl);
Cpl=(mu-LSL)/(3*sigma);
Cpk=min(Cpu,Cpl);
text({mu,1.15*rsqrt2pi/sigma},"Cpk= ",Cpk);
text({mu,1.35*rsqrt2pi/sigma},"Cpu= ",Cpu);
text({mu,1.25*rsqrt2pi/sigma},"Cpl= ",Cpl);
text({mu,1.05*rsqrt2pi/sigma},"Estimated Yield= ",yield);
) /* Close Graph Box parenthesis*/
); /* Close New Window parenthesis*/

Thursday, July 30, 2009

Process Capability Measures Cp and Cpk: A JMP JSL Demostration

I am often asked about the diffence between Cp and Cpk. Usually it is followed up by a question on why there is a need for two measures. I then answer that while Cpk is the real capability, Cp reflects the potential capability that can still be achieved just by centering your process. This is a difficult concept to grasp if just verbally described, so I usually illustrate this using a graphical demostration.
This JMP script demostrates the differences between the two Process Capability Measures Cp and Cpk.


The JMP JSL Script




dlg = Dialog(
V List(
V List(
"Cp Parameters",
"",
Line Up( 2,
/*"Mean", mu = Edit Number(0),*/
"Standard Deviation", sigma = Edit Number( 1 )
),
"",
"",
"Define Specifications",
"",
Line Up( 2, "USL ", upspecs = Edit Number( 2 ) ),
Line Up( 2, "LSL ", lowspecs = Edit Number( -2 ) )
),
H List( Button( "OK" ), Button( "Cancel" ) )
)
);


If( dlg["Button"] == -1,
Throw( "User cancelled" )
);
Remove From( dlg );
Eval List( dlg );


/*ADDED line for Cp only*/
LSL = lowspecs;
USL = upspecs;
mu = lowspecs + (upspecs - lowspecs) / 2;
mid = (upspecs - lowspecs);
/*END of added line*/


rsqrt2pi = 1 / Sqrt( 2 * Pi() );

New Window( "Process Capability Demostration",
V List Box(
H List Box(
Panel Box( "Cpk Window",
T1=Text Box ("Move the Handle in the curve to change the value of the Mean"),
g1 = Graph Box(
FrameSize( 425, 400 ),
X Scale( mu - 8 * sigma, mu + 8 * sigma ),
Y Scale( 0, 1.40 * rsqrt2pi / sigma ),
Double Buffer,
Pen Color( "blue" ),
Pen Size( 1 ),
Text Size( 12 ),
Text Color( "black" ),
Y Function( Normal Density( (x - mu) / sigma ) / sigma, x ); /*Y-scale is Normalized to Z-scores*/
Y Function(
Normal Density( (x - mu) / sigma ) / sigma,
x,
fill( 20 ),
Max( LSL )
); /*Fill low*/
Y Function(
Normal Density( (x - mu) / sigma ) / sigma,
x,
fill( 20 ),
Min( USL )
); /*Fill high*/
Pen Color( "red" );,
Pen Size( 1 ),
Text Size( 10 ),
Text Color( "black" ),
X Function( LSL, y );
Handle( mu, rsqrt2pi / sigma, mu = x;g2<<reshow; );
g2 << reshow;
Handle( LSL, 0.45 * rsqrt2pi / sigma, LSL = x );
g2 << reshow;
Handle( USL, 0.45 * rsqrt2pi / sigma, USL = x );
X Function( USL, y );
delta = mu - LSL;
Text( {mu, 0.85 * rsqrt2pi / sigma}, "mu ", mu, " sigma ", sigma );
Text Color( "red" );
Text( {LSL, 0.45 * rsqrt2pi / sigma}, "LSL= ", LSL );
Text( {USL, 0.55 * rsqrt2pi / sigma}, "USL= ", USL );
Pen Color( "blue" );,
Pen Size( 1 ),
Text Size( 11 ),
Text Color( "blue" ),
Cp = (USL - LSL) / (6 * sigma);
Cpu = (USL - mu) / (3 * sigma);
Zu = (USL - mu) / sigma;
Zl = (LSL - mu) / sigma;
yield = Normal Distribution( Zu ) - Normal Distribution( Zl );
Cpl = (mu - LSL) / (3 * sigma);
Cpk = Min( Cpu, Cpl );
Text( {mu, 1.25 * rsqrt2pi / sigma}, "Cpk= ", Cpk );
Text( {mu, 1.15 * rsqrt2pi / sigma}, "Cp= ", Cp );
Text( {mu, 1.05 * rsqrt2pi / sigma}, "Estimated Yield= ", yield );
) /* Close Graph Box parenthesis*/
),
Panel Box( "Cp Window",
T2=Text Box ("Move the Handle in the curve to change the value of the Sigma");,
g2 = Graph Box(
FrameSize( 425, 400 ),
X Scale( mu - 8 * sigma, mu + 8 * sigma ),
Y Scale( 0, 1.40 * rsqrt2pi / sigma ),
Double Buffer,
Handle( mu, rsqrt2pi / sigma, sigma = rsqrt2pi / y; g1<<reshow; );
delta = mu - LSL;
USL2 = mu + delta;
Pen Color( "red" );,
Pen Size( 1 ),
Text Size( 10 ),
Text Color( "black" ),
X Function( LSL, y );
X Function( USL2, y );
Text( {mu, 0.85 * rsqrt2pi / sigma}, "mu ", mu, " sigma ", sigma );
Text Color( "red" );
Text( {LSL, 0.45 * rsqrt2pi / sigma}, "LSL= ", LSL );
Text( {USL2, 0.55 * rsqrt2pi / sigma}, "USL= ", USL2 );
Pen Color( "blue" );,
Pen Size( 1 ),
Text Size( 11 ),
Text Color( "blue" ),
Cpu = (USL2 - mu) / (3 * sigma);
Zu = (USL2 - mu) / sigma;
Zl = (LSL - mu) / sigma;
yield2 = Normal Distribution( Zu ) - Normal Distribution( Zl );
Cpl = (mu - LSL) / (3 * sigma);
Cp2 = (USL2 - LSL) / (6 * sigma);
Text( {mu, 1.15 * rsqrt2pi / sigma}, "Cp= ", Cp2 );
Text( {mu, 1.05 * rsqrt2pi / sigma}, "Estimated Yield= ", yield2 );
Pen Color( "blue" );,
Pen Size( 1 ),
Text Size( 12 ),
Text Color( "black" ),
Y Function( Normal Density( (x - mu) / sigma ) / sigma, x ); /*Y-scale is Normalized to Z-scores*/
Y Function(
Normal Density( (x - mu) / sigma ) / sigma,
x,
fill( 20 ),
Max( LSL )
); /*Fill low*/
Y Function(
Normal Density( (x - mu) / sigma ) / sigma,
x,
fill( 20 ),
Min( USL2 )
); /*Fill high*/
)
)
)
)/*END Of BORDER BOX*/
); /* Close New Window parenthesis*/

T1<<Text Color("BLUE");
T2<<Text Color("BLUE");

Sunday, July 26, 2009

Chebyshev's Inequality to Roughly Estimate Area Under an Unknown Probability Density Curve: Reposted from www.SixSigmaPractice.multiply.com

I have always been fascinated by this generalized area under the curve theorem.
Though the estimate in itself is very weak, Chebyshev's inequality provides a very strong statistical basis for control charting.
Here is a utility that compares the actual area under the curve against to that estimated by Chebyshev's inequality.


The JMP JSL Script




Clear Globals();
new=EXPR(dt=open());
use_curr=expr(dt=Current Data Table());
if(is empty(Current Data Table()),new,use_curr);
bound=1.5;
j = 1;
col_list = {};
For( j = 1, j <= N Col( dt ), j++,
col_list[j] = Column( j ) << get name
);


COMM_RUN = Expr(
col = Column( col_name );
modelling=col<<get modeling type;
CONT=EXPR(
val1 = col << get as matrix;
counter = N Rows( val1 );
T_counter = 0;
mu = Mean( val1 );
sigma = Std Dev( val1 );
i = 1;
For( i = 1, i <= counter, i++,
If( val1[i, 1] <= mu + bound * sigma & val1[i, 1] >= mu - bound * sigma,
T_counter = T_counter + 1;
i = i + 1;
,
i = i + 1
)
);

Actual = T_counter / counter * 100;
T_estimate = (1 - (1 / (bound ^ 2))) * 100;
);
NON_CONT=EXPR(Throw ("Data Column does not contain a continous variable data"));
if(modelling=="Continuous",CONT,NON_CONT);
);

COMM_PRINT = Expr(
PRINT_TEXT = "Actual area inside mean +/- " ||char(bound) || "*sigma is " || Char( round(Actual,2) ) || " while Chebyshev's inequality estimate is " || Char( round(T_estimate,2) );
PRINT_VALUES = "Mean is equal to " ||char(round(mu,3)) || ". Sigma is equal to " ||char(round(sigma,3)) || ". The bounded interval is equal to " ||char(round(mu-bound*sigma,3)) || " to " ||char(round(mu+bound*sigma,3)) || ".";
Print( PRINT_VALUES );
Print( PRINT_TEXT );
);


COMM_OUTPUT = Expr(
OUTPUT_REPORT = New Window( "Results",
Border Box(
Left( 10 ),
Panel Box( "Simulation Result for " || char(col),
Text Box(" "),
V LIST BOX(
Text Box( "" ),
Text Box( PRINT_VALUES ),
Text Box( " " ),
Text Box( PRINT_TEXT ),
Text Box(" "),
Text Box( "sixsigmapractice.multiply.com" )
)
)
)
)
);

New Window( "Interface",
Border Box(
Left( 10 ),
Panel Box( "Set values and click on RUN",
V List Box(
V List Box(
H List Box(
Text Box( "Set Bound = k" ),
Text Box( " " ),
combo_list = Combo Box(
{"1.5", "2", "2.5", "3", "3.5", "4", "4.5", "5", "5.5", "6"},
COMBO_COMM = Expr(
k = combo_list << getselected;
bound = Num( k );
);
COMBO_COMM;
),

),
Text Box( " " ),
H List Box(
Text Box( "Select Column" ),
Text Box( " " ),
col_select = Combo Box( col_list ),
COL_COMM = Expr( col_name = col_select << get );
COL_COMM;
)
),
Text Box( " " ),
Panel Box( "Command Button",
Button Box( "RUN ESTIMATE",
COMBO_COMM;
COL_COMM;
COMM_RUN;
COMM_PRINT;
COMM_OUTPUT;
OUTPUT_REPORT << reshow;
OUTPUT_REPORT<<move window(250,50)
)
)
)
)
)
);

Sigma Level as a Measure of Process Capabiltity (Reposted from www.SixSigmaPractice.multiply.com

There are many available measures of Process Capability.
In fact anything that relates process variation to specification
limits,and measures how often the process meets these specifications can be considered as a measure of Process Capability.
Process Capability can be measured either by Percent Yield, Percent Defect, Cp, Pp, Cpk, Ppk, or Sigma Level. This JSL script uses JMP's graphical capability to demostrate how the standard Normal Curve defines the relationships between the Sigma Level, percent Yield, and percent defect.
 
Note: You may use freely but the author will appreciate it the author will be given credit, and this webpage will be sited.
Reynald Francisco
http://www.sixsigmapractice.multiply.com/



The JMP JSL Script

When the JMP script is run, an initial dialog box would prompt the user the input initial values as shown below.
Input Dialog Box:




The output image is a graph as shown below:




The JMP JSL Script is shown below::

dlg = Dialog(
V List(
V List(
"ENTER THE FOLLOWING INFORMATION:",
"",
V List(
"Input Option",
V List(
TestType = Radio
Buttons( "YIELD RATE", "DEFECT RATE", "SIGMA LEVEL" ),
Line Up( 2, "Input
Value ", x = Edit Number( 0.5 ) )
)
),
"",
"Note: Input Yield
Rate and Defect Rate in decimal format."
),
H List( Button( "OK" ),
Button( "Cancel" ) )
)
);

If( dlg["Button"] == -1,
Throw(
"User cancelled" )
);
Remove From( dlg );
Eval List( dlg );

If(
TestType != 3 & x >= 1,
Caption( "Input Yield Rate
and Defect Rate in decimal format. Right click to close message." );
Throw(
"User cancelled" );,
TestType != 3 & x <= 0,
Caption( "Input
value is not valid. Right click to close message." );
Throw( "User
cancelled" );,
TestType == 3 & x < 0,
Caption( "Input value is
not valid. Right click to close message." );
Throw( "User cancelled" );
);

mu = 0;
sigma = 1;
rsqrt2pi = 1 / Sqrt( 2 * Pi() );

If(
TestType == 3, SigmaLevel = x,
TestType == 1, SigmaLevel =
Normal Quantile( x ),
TestType == 2, SigmaLevel = Normal Quantile( 1 - x )
);

New Window( "Sigma Level Demostration",
Graph Box(
FrameSize( 900, 500 ),
X Scale( -10, 10 ),
Y Scale( 0, 0.5 ),
Double Buffer,
Pen Color( "blue" ),
Pen Size( 1 ),
Text Size( 12
),
Text Color( "black" ),
Y Function( Normal Density( (x - mu) / sigma )
/ sigma, x ); /*Y-scale is Normalized to Z-scores*/
If( TestType == 2,
Y
Function( Normal Density( (x - mu) / sigma ) / sigma, x, fill( 1 ), Min(
SigmaLevel ) ),
Y Function( Normal Density( (x - mu) / sigma ) / sigma, x,
fill( 1 ), Max( SigmaLevel ) )
);
Pen Color( "red" );,
Pen Size( 1
),
Text Size( 10 ),
Text Color( "black" ),
X Function( SigmaLevel, y
);
Handle( SigmaLevel, 0.45 * rsqrt2pi / sigma, SigmaLevel = x );
Text
Color( "black" );
Text( {SigmaLevel, 0.45 * rsqrt2pi / sigma}, "<--Move
this point" );
Text Color( "red" );
Text( {SigmaLevel, 0.55 * rsqrt2pi /
sigma}, "Sigma Level= ", SigmaLevel );
Pen Color( "blue" );,
Pen Size( 1
),
Text Size( 11 ),
Text Color( "blue" ),
Z = (SigmaLevel - mu) /
sigma;
Yield = Normal Distribution( Z );
Defect = (1 - Yield);
Text(
{mu, 1.15 * rsqrt2pi / sigma}, "YIELD= ", yield * 100, "%" );
Text( {mu,
1.05 * rsqrt2pi / sigma}, "DEFECT= ", defect * 100, "%" );
) /* Close Graph
Box parenthesis*/
); /* Close New Window parenthesis*/





Saturday, July 11, 2009

Extending Your JMP's Capability Thru Scripting

If your are a JMP user do you know that you can increase your JMP's capability by leaps and bounds through scripting?

Yes you can! I do create scipts which utilities range from an ordinary alarm clock, mail sender, matrix solver, to report generator, and so on. Some of my work are shared online and can be found here:
http://sixsigmapractice.multiply.com/

http://www.sas.com/apps/demosdownloads/jmpFileExchange_PROD__sysdep.jsp?packageID=000416&jmpflag=Y&searchvar=userName&searchval=Reynald%20Francisco

In my multiply account, i do post many JSL scripts. In here i will try to foucs more on teaching how to script.

Till next entry!
 
Custom Search