<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />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:
| SampleID | Assay#1 | Assay#2 | Reference |
| 307HV093 | Negative | Negative | Negative |
| 307HV093 | Negative | Negative | Negative |
| 307HV094 | Positive | Positive | Positive |
| 307HV094 | Positive | Positive | Positive |
| 307HV095 | Positive | Positive | Positive |
| 307HV095 | Positive | Positive | Positive |
| 307HV096 | Positive | Positive | Positive |
| 307HV096 | Positive | Positive | Positive |
| 307HV097 | Negative | Negative | Negative |
| 307HV097 | Negative | Negative | Negative |
| 307HV098 | Negative | Negative | Negative |
// 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 <
clusterDlg = NewWindow("2x2 Contingency Tables & Statistics", //create a new window for User Selection of Columns
BorderBox(left(3),top(2),
VListBox(
TextBox("Comparing Assays"),
HlistBox(
VListBox(
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
LineupBox(NCol(2),Spacing(3),
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
),
),
PanelBox("Action",
LineupBox(NCol(1),
ButtonBox("OK",
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(
Count(1),
Total %(0),
Col %(0),
Row %(0),
Expected(0),
Deviation(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<<Tests(0);
cont<<Agreement Statistic(1); //turn on
rcont=cont<<report; //a reference to the report
/*rcont["Agreement Statistic","Bowker's Test"]<
for(i=1, i<=nitems(rcont), i++,
kap=rcont(Contingency Table(i)["Agreement Statistic","Kappa Coefficient"]);
kapset=kap[NumberColbox("Kappa")];
kap<
kap<
rcont(SendToReport(
Dispatch( //maybe dispatch would work better?
{"Agreement Statistic","Kappa Coefficient"},
"Kappa",
NumberColBox,
{Set Format( 8, 3 ), Set Conditional Format( "Correlation" )}
));,*/
),//H List Box
"copy of 2x2 Contingency", //second tab
//testval = reportcont[TableBox(1)]; need to figure out how to grab the contingency table values
//matrixbox(testval<
))//tabbox
); //window, removing the ";"" results in the dialog window not closing
clusterDlg<<CloseWindow), //OK button box
ButtonBox("Cancel",
clusterDlg<<CloseWindow),
TextBox(" "),
ButtonBox("Remove", //remove selected columns from the two assay listboxes
colListY<<RemoveSelected;
colListB<<RemoveSelected;
),
ButtonBox("Recall",notImplemented), //hasn't been programmed
ButtonBox("Help",notImplemented)) //hasn't been programmed
)// panel box
)//hlistbox
)//vlistbox
)//borderbox
);//window (cluster dlg)