BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar

Community Trekker


Sep 27, 2013

JSL: How to use subscripts to manipulate contingency reports

Hi, I'm trying to create a dynamic script that will create contingency tables in a report and associated statistics based on user selected column assignments. This is my first attempt at JSL so I'm an absolute beginner. I have the user form and table creation working but I'm struggling with understanding how to refer to the different parts of the generated report in order to do simple things like set the decimal format for kappa statistic. Eventually I'd like to also be able to extract the values from the displayed contingency tables do calculations and display the results somewhere else in the report. I've been reading about subscripts and am trying to use that concept to dig into the report but I can't figure out how to use them correctly. I know I need to get a good understanding on this concept because the user will be able to select from 2 columns to 10 and therefore the script can produce anywhere from 1 to 25 contingency tables all of which I need to keep track of and refer to later. So I know it might be best to assign variables to each but I can't figure that out either since the building of the tables is automated by JMP rather than using something like a For loop. Any help is very much appreciated I'd also love any feedback on JSL scripting unrelated to my specific questions (e.g. best practices, etc.) for learning purposes.

The part I'm struggling with is the section that is commented out with /*------*/. Sorry for the excessive commenting but being my first script I'm try to capture concepts that my future self can look back at. I'm using JMP 10.0.1 release 2 on Windows 7. I couldn't find a sample data set already in JMP that is typical of what I'm working with so here's a miniature version:


// Based on "Constructing Display Trees" pg 363 of JMP Scripting Guide for JMP 10

clear globals();

Names Default To Here(1); //all non scoped variables are local

if(isempty(dt = currentdatatable()), dt = open(pickfile("Choose an input data file:")));

//savedir = pickdirectory("Choose a destination folder for the summary files:"); //use this later

dt = currentDataTable(); nc = ncol(dt); //get the # of columns in the table

lbWidth = 130;

notImplemented = expr(New Window("Feature Not Implemented Yet",<<Modal, ButtonBox("OK"))); //I have no idea what <<modal does

clusterDlg = NewWindow("2x2 Contingency Tables & Statistics", //create a new window for User Selection of Columns



TextBox("Comparing Assays"),



PanelBox("Select Columns", //box to list columns available

colListData=ColListBox(All,width(lbWidth),nLines(min(nc,10))) //listbox of all columns in the data table using standard width lbWidth(130)



PanelBox("Cast Selected Columns into Roles", //box to designate columns for analysis


ButtonBox("Assay, Columns",

colListY<<Append(colListData<<GetSelected)), //take the selected columns and add them to the colListY listbox

colListY = ColListBox(width(lbWidth),nLines(5)), // number of lines is limited to 5 and this can be expanded but should be sufficient for most studies

ButtonBox("Reference or Comparative Test, Column",

colListB<<Append(colListData<<GetSelected)), //designate 1 column as reference or a "comparative" test to compare to the others (this will end up as the X and affect future statistics)

colListB = ColListBox(width(lbWidth),nLines(5)) //number of lines is limited to 5, increasing results in additional comparisons

//the order will be 1st reference (X) to each of the assays (Y), 2nd reference to each of the assays and so on






contwin=NewWindow("Contingency Results "||char(format(as date(today()),"ddMonyyyy")),

      Tabbox("Contingency Table",   HListBox(

                  cont = Contingency( //cont is a reference to the platform (analysis layer)

                  Y(colListB<<get items),

                  X(colListY<<get items)); //contingency

                  cont<<Contingency Table(


                        Total %(0),

                        Col %(0),

                        Row %(0),



                        Cell Chi Squared(0),

                        Col Cum(0),

                        Col Cum %(0),

                        Row Cum(0),

                        Row Cum %(0),


                  cont<<size window(500,700); // I want the contingency table to stop cutting off words but I can't seem to make it bigger

                  cont<<Mosaic Plot(0); //turn off


                  cont<<Agreement Statistic(1); //turn on              


                  rcont=cont<<report; //a reference to the report

                  /*rcont["Agreement Statistic","Bowker's Test"]<<close(1)

                  for(i=1, i<=nitems(rcont), i++,

                  kap=rcont(Contingency Table(i)["Agreement Statistic","Kappa Coefficient"]);


                  kap<<set format(8,3);

                  kap<<set Conditional Format("Correlation");



                        Dispatch( //maybe dispatch would work better?

                              {"Agreement Statistic","Kappa Coefficient"},



                              {Set Format( 8, 3 ), Set Conditional Format( "Correlation" )}


),//H List Box

"copy of 2x2 Contingency", //second tab

  • v list box(

//testval = reportcont[TableBox(1)]; need to figure out how to grab the contingency table values

//matrixbox(testval<<get as matrix))



); //window, removing the ";"" results in the dialog window not closing

clusterDlg<<CloseWindow), //OK button box



TextBox(" "),

ButtonBox("Remove", //remove selected columns from the two assay listboxes




ButtonBox("Recall",notImplemented), //hasn't been programmed

ButtonBox("Help",notImplemented))  //hasn't been programmed

)// panel box




);//window (cluster dlg)