Friday, June 22, 2012

Quincunx using JMP's JSL: Basic Statistical Concepts of Center, Spread, Shape, and Stability

I had a new job and it's now harder for me to find time to update this blog or to even write JMP Scripts. While I enjoy my new function a lot, I from time to time miss writing scripts so badly that I just spend a few hours sitting down to design a function and then crudely write the JSL that will execute it. This one I'm sharing to the world hoping that I will comeback to me improved (and still free of charge, I hope).
I would really appreciate it if you would have the chance to use it that you would somehow mention the source and my name.
Here you go, a quincunx version in JMP (written in JMP 8, please don't run using JMP 7, the reports are messed-up on that version.):


//===================================
Clear Globals();
/************************************** DECLARE VARIABLES****************************/
//////////////////////////////////////////////////////////////////////////////////////
samples = 1000;
jval = 20;
kval = 5;
a = -kval;
b = jval;
droppoint = 0;
val = droppoint ;
x = 1;
y = 0;
SUM_BOUNCE = 0;
looping = 1;
PIN_LEVELS = jval;
PIN_WIDTH = kval * 2 - 1;
SAMPLES = samples;
m = 1;
n = 1;
o = 1;
loop2 = 0;
/********************************EXPRESSION******************************************/
//////////////////////////////////////////////////////////////////////////////////////
dist_com = Expr(
 dist = tb << Distribution(
  Stack( 1 ),
  Continuous Distribution(
   Column( :VALUE ),
   Quantiles( 0 ),
   Moments( 0 ),
   Horizontal Layout( 1 ),
   Vertical( 0 ),
   Outlier Box Plot( 0 )
  ),
  SendToReport(
   Dispatch( {"VALUE"}, "1", ScaleBox, {Min( -6 ), Max( 6 )} ),
   Dispatch(
    {"VALUE"},
    "Distrib Histogram",
    FrameBox,
    {Frame Size( 500, 200 ), DispatchSeg(
     HistSeg( 1 ),
     {Fill Color( "Medium Dark Green" ), Histogram Color( 20 )}
    )}
   )
  )
 );
 dist << minimize window;
 CC = Control Chart(
 Sample Label( Empty() ),
 Group Size( 1 ),
 KSigma( 3 ),
 Chart Col( :VALUE, Individual Measurement ),
 SendToReport(
  Dispatch( {}, "Control Chart", OutlineBox, Set Title( "Consistency" ) ),
  Dispatch(
   {},
   "Individual Measurement of VALUE",
   OutlineBox,
   Set Title( "Position" )
  ),
  Dispatch(
   {"Individual Measurement of VALUE"},
   "2",
   ScaleBox,
   {Format( "Fixed Dec", 12, 1 ), Min( -10 ), Max( 10 )}
  ),
  Dispatch(
   {"Individual Measurement of VALUE"},
   "1",
   ScaleBox,
   {Min( 0 ), Max( 1000 ), Inc( 5 ), Rotated Labels( 1 )}
  ),
  Dispatch(
   {"Individual Measurement of VALUE"},
   "IR Chart",
   FrameBox,
   Frame Size( 500, 200 )
  ),
  Dispatch(
   {"Individual Measurement of VALUE"},
   "IR Chart",
   FrameBox( 2 ),
   Frame Size( 70, 200 )
  )
 )
);
 CC << minimize window;
 CCR = CC << report;

 distr = dist << report;
 cc << minimize window;
 dist<< minimize window;
 wind << Show Window;

 wind[List Box( 4 )] << append( distr[framebox( 1 )] );
 wind[List Box( 4 )] << append( ccr[framebox( 1 )] );
 CC< dist< wind << Show Window;
);


/************************************** CREATE TABLE*********************************/
//////////////////////////////////////////////////////////////////////////////////////
tb = New Table( "BOUNCE RECORD", Add Rows( SAMPLES ) );
tb << minimize window();

For( m = 1, m <= PIN_LEVELS - 2, m++,
 tb << New Column( "PIN" || Char( m ), Nominal )
);
col = Column( 1 ) << set name( "VALUE" );
col << get name;
/************************************** CREATE WINDOW********************************/
//////////////////////////////////////////////////////////////////////////////////////

wind = New Window( "Basic Statistics Concept",
 VL = V List Box(
  Graph Box(
   title( "Center, Spread, Shape, Consistency" ),
   X Scale( -kval - 1, kval + 1 ),
   Y Scale( 0, jval ),
   framesize( 500, 200 ),
   Handle(droppoint ,jval,wait(2);droppoint = x; val = droppoint );
   Fill Color( "RED" ),          

   For( b = 0, b <= jval - 1, b++,
    For( a = -kval, a <= kval, a++,
     If(
      Mod( b, 2 ) == 1, Circle( {a + 0.5, b}, .1, "FILL" ),
      Circle( {a, b}, .1, "FILL" ),
     )
    )
   ),          
   Fill Color( "GREEN" ),
   r = Circle( {val, jval - y - 0.9}, .5, "FILL" )
  )





 )
);
//976,8000
////48,468

/************************************ EXTRA FUNCTIONS********************************/
//////////////////////////////////////////////////////////////////////////////////////
wind[axisbox( 1 )] << delete;
Wait( 0.1 );
loop = 0;
For( loop = 0, loop <= samples, loop++,
 x = 1;
 y = 0;
 If( loop == 1,
  Wait( 0 );
  Eval( dist_com );
 ,
  If( loop > 1,
   //dist << close window;
   //cc << close window;
   wind[framebox( 3 )] << delete;
   wind[framebox( 2 )] << delete;
   Eval( dist_com );

  )

 );
 wind << Show Window;
 For( y = 0, y < jval - 2, y++,        

  Wait( 0.05 );
  wind << reshow;
  rand = Random Binomial( 1, 0.5 );

  If( rand == 0,
   val = val + 0.5,
   val = val - 0.5
  );

  valbounce = If( rand == 0, -1, 1 );
  Column( y + 2 )[loop + 1] = valbounce;
  SUM_BOUNCE = SUM_BOUNCE + (valbounce / 2);
 );
 Column( 1 )[loop + 1] = SUM_BOUNCE;
 loop2 = 0;
 //wind[framebox(2)]< val = 0;
 drop = SUM_BOUNCE;
 wind << reshow();
 SUM_BOUNCE = 0;
 

);


//==================================

No comments:

Post a Comment

 
Custom Search