Monday, July 27, 2009

When Xbar-R wont work...

I am trying to build a case. I want to argue that there are instances that the commonly used control chart Xbar-R does not always work for manufacturing data. This is even when the famous Central Limit Theorem is invoked as a justification of the method.
In here I am developing a JMP JSL to demonstrate it's weaknesses.
I am not yet done, but almost 80% complete. This script is already operational, but not yet as I intended it to be.

Hope you find it useful. I will post the complete blog when I find the time.

Regards,
Reynald Francisco




The JMP JSL Script





Clear Globals();

Run_Num = 1;
//FUNCTIONS

GEN_DATA = Expr(
a = 1;
b = 1;
//Generate Subgroup Means
SubMeans_Matrix = {};
For( a = 1, a <= SubCount, a++,
SubMeans_Matrix[a] = mu + (SigmaBet * Random Normal())
);



a = 1;
b = 1;
i = 1;
NormList = {};
NormTemp = {};
NormData = {};
NormData_b = {};
For( a = 1, a <=SubCount, a++,

b = 1;
For( b = 1, b <= SubSize, b++,
NormTemp[i] = SubMeans_Matrix[a] + (SigmaWith * Random Normal());
NormData_b = NormTemp[i];
NormTemp = {};
NormData = Matrix( NormData );
NormData_b = Matrix( NormData_b );
NormData = NormData || NormData_b;
NormData_b = {};
);
NormList = Matrix( NormList );
NormData = Matrix( NormData );
NormList = NormList |/ NormData;
NormData = {};
);


a = 1;
b = 1;
NormMatrix = Matrix( NormList );


//GENERATE RANDOM DATA;


b = 1;
SigmaWith_Matrix = {};
For( b = 1, b <= SubCount, b++,
SigmaWith_Matrix[b] = (Max( NormMatrix[b, 0] )) - Min( NormMatrix[b, 0] )
);


//sigma = Std Dev( NormMatrix );
//SigmaTot = sigma;
//SigmaWith = Mean(SigmaWith_Matrix)*A2_constant/3;
//SigmaBet = Sqrt( (SigmaTot ^ 2) - (SigmaWith ^ 2) );
SigmaTot_new = SigmaTot;
SigmaWith_new = SigmaWith;


a = 1;
b = 1;
dt = New Table( "Simulation Data-" || Char( Run_Num ) );
m_col = dt << New Column( "Measurement Number", formula( Row() ) );
m_col << set modelling type( ordinal );
For( a = 1, a <= SubSize, a++,
col = dt <<New Column( "Measurement" || Char( a ) );
col << Set Values( NormMatrix[0, a] );
);

Mean_Matrix = {};
a = 1;
b = 1;
For( b = 1, b <= SubCount, b++,
Mean_Matrix[b] = Mean( NormMatrix[b, 0] )
);
Mean_Matrix = Matrix( Mean_Matrix );
col = dt << New Column( "Average Measurement" );
col << Set Values( Mean_Matrix );

SigmaWith_Matrix = Matrix( SigmaWith_Matrix );
col = dt << New Column( "Measurement Range" );
col << Set Values( SigmaWith_Matrix );

Run_Num = Run_Num + 1;
dt <<Select All Rows;
dt << colors( 5 );
dt << markers( 8 );
); //END OF EXPRESSION: GEN_DATA


GEN_CHART = Expr(
OUT_WINDOW << Append(
CChat = Panel Box( "Resulting Control Chart",
Overlay Plot(
X( :Measurement Number ),
Y( :Average Measurement ),
Y Axis[1] << {{Scale( Linear ), Format( "Best" ), Min(
Col Mean( Column( "Average Measurement" ) ) - 1.10 * A2_constant * Col Mean( Column( "Measurement Range" ) )
), Max(
Col Mean( Column( "Average Measurement" ) ) + 1.10 * A2_constant * Col Mean( Column( "Measurement Range" ) )
), Inc( 1 ), Add Ref Line(
Col Mean( Column( "Average Measurement" ) ) - A2_constant * Col Mean( Column( "Measurement Range" ) ),
Solid,
Dark Red
), Add Ref Line(
Col Mean( Column( "Average Measurement" ) ) + A2_constant * Col Mean( Column( "Measurement Range" ) ),
Solid,
Dark Red
), Add Ref Line( Col Mean( Column( "Average Measurement" ) ), Dashed, Red )}},
Separate Axes( 1 ),
Connect Points( 1 ),
:Average Measurement( Connect Color( 21 ) ),
SendToReport(
Dispatch( {}, "Overlay Plot", OutlineBox, Set Title( "Control Chart for Simulated Data-" || Char( Run_Num ) ) )
),
SendToReport(
Dispatch(
{},
"106",
ScaleBox,
{Scale( Linear ), Format( "Fixed Dec", 3 ), Min(
Col Mean( Column( "Average Measurement" ) ) - 1.10 * A2_constant *
Col Mean( Column( "Measurement Range" ) )
), Max(
Col Mean( Column( "Average Measurement" ) ) + 1.10 * A2_constant *
Col Mean( Column( "Measurement Range" ) )
), Inc( Round( (2 * A2_constant * Col Mean( Column( "Measurement Range" ) )) / 20, 2 ) )}
),
Dispatch(
{},
"101",
ScaleBox,
{Scale( Linear ), Format( "Best" ), Min( 0.5 ), Max( SubCount + 0.5 ), Inc( 1 ), Minor Ticks( 0 ),
Rotated Labels( 1 )}
),
Dispatch(
{},
"Overlay Plot",
FrameBox,
{Frame Size( 840, 300 ), DispatchSeg( LineSeg( 1 ), {Line Color( "Medium Dark Blue" )} )}
)
)
)
)//END OF GRAPH BOX
);//END OF NEW WINDOW

Run_Num = Run_Num + 1;
);//END OF EXPRESSION GEN_CHART


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

//Define Subgrouping (limit from 2-9 for XbarR charts)
//Define intial average
//Define initial Sigma within
//Get user information through a dialog box



SamplingSizes = {"2", "3", "4", "5", "6", "7", "8", "9"};
SubgroupSizes = {"20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35"};

dlg = Dialog(
"When Xbar-R will not work: A JMP demonstration",
" ",
"Enter the following information to begin",
" ",
V List(
V List(
" Population parameter:",
"",
Line Up( 2, " Mean", mu = Edit Number( 0 ), " Standard Deviation", sigma = Edit Number( 1 ) ),
"",
"",
" Define Sampling Plan:",
"",
H LIST(
V LIST( " Subgroup Size ", H LIST( " ", n = Combo Box( SamplingSizes ) ) ),
" ",
V LIST( " Number of Subgroups ", H LIST( " ", m = Combo Box( SubgroupSizes ) ) )
)
)
),
" ",
H List( Button( "OK" ), Button( "Cancel" ) )
);


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




SubSize = Match( n, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9 );
SubCount = Match( m,
1, 20,
2, 21,
3, 22,
4, 23,
5, 24,
6, 25,
7, 26,
8, 27,
9, 28,
10, 29,
11, 30,
12, 31,
13, 32,
14, 33,
15, 34,
16, 35
);

A2_constant = Match( SubSize, 2, 1.8806, 3, 1.0231, 4, 0.7286, 5, 0.5768, 6, 0.4833, 7, 0.4193, 8, 0.3725, 9, 0.3367 );

SigmaTot = sigma;
SigmaWith = (SigmaTot / A2_constant) / 3;
SigmaBet = Sqrt( (SigmaTot ^ 2) - (SigmaWith ^ 2) );



/**********************************CODE OUTPUT INTERFACE*********************************************/


//Define the output window
OUT_WINDOW = New Window( "When Xbar-R will not work: A JMP demonstration",
Border Box(
TOP( 5 ),
Left( 5 ),
Panel Box( "MOVE THE SLIDER BOXES BELOW TO ADJUST THE RELATIVE VALUES OF SIGMAS:",
V List Box(
H List Box(
V List Box(
NormCurve = Graph Box(
FrameSize( 500, 300 ),
Y Scale( 0, y = 0.8 * rsqrt2pi / (sigma / Sqrt( SubSize )) ),
X Scale( mu - 10.0 * sigma, mu + 10.0 * sigma ),
Double Buffer,
Pen Size( 2 );
Pen Color( "red" );
Text Color( "red" );
Text( {mu + 2.0 * SigmaTot, 0.5 * y}, "Sigma Total" );
Y Function( Normal Density( ((x - mu) / SigmaTot) ), x );
Pen Color( "blue" );
Text Color( "blue" );
Text( {mu + 2.5 * SigmaWith, 0.1 * y}, "Sigma Within" );
Y Function( Normal Density( ((x - mu) / SigmaWith) ), x );
Pen Color( "green" );
Text Color( "green" );
Text( {mu + 3.0 * SigmaBet, 0.3 * y}, "Sigma Between" );
Y Function( Normal Density( ((x - mu) / SigmaBet) ), x );
),


H List Box(
Text Color( "black" );
T1 = Text Box( " SIGMA BETWEEN: " );,
SB1 = Slider Box(
0.5 * SigmaTot,
10 * SigmaTot,
SigmaBet,
SigmaTot = Sqrt( SigmaWith ^ 2 + SigmaBet ^ 2 );
NormCurve << reshow;
Tri << reshow;
SB2 << reshow;


);
),
H List Box(
Pen Color( "blue" );
T2 = Text Box( " SIGMA WITHIN: " );,
SB2 = Slider Box(
0.5 * SigmaTot,
10 * SigmaTot,
SigmaWith,
//SIGMA_WIDTH_EXPR;
SigmaTot = Sqrt( SigmaWith ^ 2 + SigmaBet ^ 2 );
NormCurve << reshow;
Tri << reshow;
SB1 << reshow;
)
);



),
Tri = Graph Box(
framesize( 300, 300 ),
X Scale( -0.5, 10.5 * SigmaTot ),
Y Scale( -0.50, 10.5 * SigmaTot ),
XCOR = {0, SigmaWith, 0, 0};
YCOR = {0, 0, SigmaBet, 0};
XCOR = Matrix( XCOR );
YCOR = Matrix( YCOR );
Pen Color( "Gray" );
Fill Color( "Gray" );
Polygon( XCOR, YCOR );
Pen Size( 2 );
Pen Color( "blue" );
Line( {SigmaWith, 0}, {0, 0} );
Pen Color( "green" );
Line( {0, 0}, {0, SigmaBet} );
Pen Color( "red" );
Line( {0, SigmaBet}, {SigmaWith, 0} );
)
),
Text Box( " " ),
H List Box(
Panel Box( "COMMAND OPTIONS",
V List Box(
Button Box( "GENERATE SIMULATED DATA", GEN_DATA ),
Button Box( "GENERATE SIMULATED DATA AND CHARTS",
GEN_DATA;
Run_Num = Run_Num - 1;
GEN_CHART;
Out_Window << Bring Window To Front;
)
)
),
Panel Box( "HELP OPTIONS",
V List Box(
Button Box( "ABOUT THE AUTHOR", Caption( "wala pa" ) ),
Button Box( "HELP LINKS", Caption( "WALA PA" ) )
)
),
Panel Box( "OTHER OPTIONS",
V List Box(
Button Box( "EXIT", OUT_WINDOW << CLOSE WINDOW ),
Button Box( "WWW.SIXSIGMAPRACTICE.COM", Web( "WWW.SIXSIGMAPRACTICE.COM" ) )
)
)
)//END OF HLIST
) //END OF BORDER BOX
) //END OF END OF PANEL BOX
) // END OF BORDER BOX
);//END OF NEW WINDOW OUT_WINDOW
T1 << font color( "GREEN" );
T2 << font color( "BLUE" );
Show( NormCurve );
NormCurve << reshow;
Tri << reshow;

Out_Window << Bring Window To Front;


No comments:

Post a Comment

 
Custom Search