Hi @ErraticAttack ,
Thanks for your feedback. I have noticed that this is the second time you've recommended the Namespace() to me ;-).
As a result, I have spent the past day and a half reading up on using NameSpace in my scripting guide, which is better than the Scripting Index, but still doesn't really give the best examples like how you are using it. Do you have any primer that is better than the JMP 14 Scripting Guide or Scripting Index on how to use Namespace in the context of how you are using it?
I have to admit I don't quite follow what you're doing and need to learn it better. However, based on your post here, and on the example code you provided on one of my other posts here, I was able to re-write my section of script that calls the first window using the Namespace(). But, I'm still not quite sure how I would script-in the subsequent windows and displays that I am able to get to work via my not-so-great scripting skills. I think it's going to take some time to learn how to use Namespace correctly before I can switch over to that programmatic method, which I would like to do.
I was able to get the graph builder of the display to update upon checking/unchecking the box to hide/exclude the data that is negative (in this case meaningless). The script below does what I want (except for updating the table box when certain data is removed from the graph), but I understand that it's not ideal from the standpoint of programming.
Thanks!,
DS
Names Default To Here( 1 );
lbWidth = 168;
dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );
// Expression to store the current settings in global variables
recallRolesS1 = Expr(
::dtchosenRecall = dtchosen
);
// Expression to clear all current settings. KW: Clear
clearRoles = Expr(
Try(
colListY << RemoveAll;
ColListX << RemoveAll;
ColListW << RemoveAll;
ColListF << RemoveAll;
colListV << RemoveAll;
)
);
// Expression to store the current settings in global variables
recallRoles = Expr(
::ycolRecall = colListY << GetItems;
::xcolRecall = colListX << GetItems;
::WcolRecall = colListW << GetItems;
::FcolRecall = colListF << GetItems;
::vcolRecall = colListV << GetItems;
::max_spRecall = max_sp_input << get;
::partVPRecall = partVP_input << Get;
);
//Function to choose the data table to model. KW: choose_data
choose_data_table = Function( {},
list = {};
For( i = 1, i <= N Table(), i++,
list[i] = Data Table( i ) << get name
);
win = New Window( "Select a data table",
<<Modal,
hb = H List Box(
Panel Box( "Choose a data table", dt = List Box( list, max selected( 1 ), dtchosen = Data Table( (dt << get selected)[1] ) ) ),
)
);
);
Part_rerun = Expr(
Close( dt_results, No Save );
NPCs_num = NPCs;
str = Eval Insert(
"report = (dtchosen<<Partition(
Y(Eval(ycols)),
X(Eval(xcols)),
Weight(Eval(wcols)),
Freq(Eval(Fcols)),
Validation(Eval(vcols)),
Informative Missing(1),
Split Best(^NPCs_num^),
Validation Portion(^partVP^),
Split History(1)
)
)<<Report;"
);
Eval( Parse( str ) );
);
Part_TB = Expr(
Part_TBWin = New Window( "Select the Best split to re-run",
<<Return Result,
<<On Validate,
Outline Box( "Partitioning Results (Select the best to re-run))",
H List Box(
V List Box(
If(
N Items( vcols ) == 1 | (N Items( vcols ) == 0 & Is Missing( PartVP ) == 0),
part_gb = Graph Builder(
Size( 579, 417 ),
Show Control Panel( 0 ),
Variables(
X( :Splits ),
Y( :Training RSquare ),
Y( :Validation RSquare, Position( 1 ) ),
Y( :RSquare Diff ),
Y( :Penalized Valid RSquare, Position( 2 ) )
),
Elements( Position( 1, 1 ), Line( X, Y( 1 ), Y( 2 ), Legend( 12 ) ), Points( X, Y( 1 ), Y( 2 ), Legend( 14 ) ) ),
Elements( Position( 1, 2 ), Line( X, Y( 1 ), Y( 2 ), Legend( 13 ) ), Points( X, Y( 1 ), Y( 2 ), Legend( 15 ) ) ),
SendToReport(
Dispatch(
{},
"graph title",
TextEditBox,
{Set Text( "Training & Validation RSquare / RSquare Diff & Penalized Valid RSquare vs. Splits" )}
)
)
),
N Items( vcols ) == 0 & Is Missing( PartVP ) == 1,
part_gb = Graph Builder(
Size( 531, 456 ),
Show Control Panel( 0 ),
Variables( X( :Splits ), Y( :Training RSquare ), Y( :Penalized Train RSquare ) ),
Elements( Position( 1, 1 ), Line( X, Y, Legend( 7 ) ), Points( X, Y, Legend( 9 ) ) ),
Elements( Position( 1, 2 ), Line( X, Y, Legend( 8 ) ), Points( X, Y, Legend( 11 ) ) )
)
),
V List Box(
Text Box(
"Warning: Data where marker is '*' have a negative R² or Validation R² > Training R².",
<<Set Font Size( 12 ),
<<Set Width( 600 )
),
If(
N Items( neg_rows ) != 0,
cb = Check Box(
"Remove bad points from graph (*'s)?",
<<Set( 0 ),
<<Set Function(
Function( {},
state = cb << Get;
If(
state == 0,
dt_results << Select Rows( neg_rows ) << Unhide;
dt_results << Select Rows( neg_rows ) << Unexclude;
dt_results << Clear Select;
dt_tb=dt_results<<Get As Report;
Part_TBWin<<Update Window,
state == 1,
dt_results << Select Rows( neg_rows ) << Hide and Exclude;
dt_results << Clear Select;
);
)
)
),
N Items( neg_rows ) == 0, cb = Text Box( "" )
),
)
),
dt_tb = dt_results << Get As Report(),
Panel Box( "Action",
Lineup Box( N Col( 1 ),
Text Box( "Re-run Partion", <<Justify Text( "Center" ) ),
Button Box( "OK",
Part_rerun;
Part_TBWin << Close Window;
),
Button Box( "Cancel",
Part_TBWin << Close Window;
Try( Close( dt_results, No Save ) );
),
Spacer Box( Size( 0, 15 ) ),
Button Box( "Relaunch",
Part_TBWin << Close Window;
Try( Close( dt_results, No Save ) );
Firstwin;
),
Spacer Box( Size( 0, 8 ) ),
Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
)
)
)
)
);
tb = dt_tb[Table Box( 1 )];
For( ri = 1, ri <= N Col( dt_results ) - 2, ri++,
dt_tb[Table Box( 1 )][Number Col Box( ri + 1 )] << Set Format( "Fixed Dec", 6, 4 )
);
tb << Set Shade Headings( 1 );
tb << Set Heading Column Borders( 1 );
tb << Set Selectable Rows( 1 );
tb << Set Click Sort( 1 );
tb << Set Row Change Function(
Function( {this},
{SelRows},
SelRows = this << Get Selected Rows;
If(
N Items( SelRows ) > 1, Throw( "Too many items selected!\!rOnly one selection possible." ),
N Items( SelRows ) == 1,
SelRows = this << Get Selected Rows;
NPCs = SelRows[1];
);
dt_results << Clear Select;
dt_results << Select rows( SelRows );
)
);
);
Part = Expr(
If(
N Items( vcols ) == 1,
dt_results = New Table( "Partition_Results",
Add Rows( max_sp ),
New Column( "Splits", Numeric, Continuous ),
New Column( "Training RSquare", Numeric, Continuous ),
New Column( "Validation RSquare", Numeric, Continuous ),
New Column( "Training RASE", Numeric, Continuous ),
New Column( "Validation RASE", Numeric, Continuous ),
New Column( "RSquare Diff", Numeric, Continuous, Formula( "Training RSquare"n - "Validation RSquare"n ) ),
New Column( "Penalized Valid RSquare", Numeric, Continuous, Formula( "Training RSquare"n - 0.05 * "Splits"n ) ),
New Column( "Training N", Numeric, Continuous ),
New Column( "Validation N", Numeric, Continuous )
),
N Items( vcols ) == 0 & Is Missing( partVP ) == 0,
dt_results = New Table( "Partition_Results",
Add Rows( max_sp ),
New Column( "Splits", Numeric, Continuous ),
New Column( "Training RSquare", Numeric, Continuous ),
New Column( "Validation RSquare", Numeric, Continuous ),
New Column( "Training RASE", Numeric, Continuous ),
New Column( "Validation RASE", Numeric, Continuous ),
New Column( "RSquare Diff", Numeric, Continuous, Formula( "Training RSquare"n - "Validation RSquare"n ) ),
New Column( "Penalized Valid RSquare", Numeric, Continuous, Formula( "Validation RSquare"n - 0.05 * "Splits"n ) ),
New Column( "Training N", Numeric, Continuous ),
New Column( "Validation N", Numeric, Continuous )
),
N Items( vcols ) == 0,
dt_results = New Table( "Partition_Results",
Add Rows( max_sp ),
New Column( "Splits", Numeric, Continuous ),
New Column( "Training RSquare", Numeric, Continuous ),
New Column( "Training RASE", Numeric, Continuous ),
New Column( "Penalized Train RSquare", Numeric, Continuous, Formula( "Training RSquare"n - 0.05 * "Splits"n ) ),
New Column( "Training N", Numeric, Continuous )
)
);
For( i = 1, i <= max_sp, i++,
dt_results:"Splits"n[i] = i
);
dt_name = dtchosen << Get Name;
For( i = 1, i <= N Rows( dt_results ), i++,
Psplit = dt_results:"Splits"n[i];
str = Eval Insert(
"report = (dtchosen<<Partition(
Y(Eval(ycols)),
X(Eval(xcols)),
Weight(Eval(wcols)),
Freq(Eval(Fcols)),
Validation(Eval(vcols)),
Informative Missing(1),
Split Best(^Psplit^),
Validation Portion(^partVP^),
Invisible
)
)<<Report;"
);
Eval( Parse( str ) );
partWinName = Report << Get Window Title;
w = Window( partWinName );
RSq_mat = w[Outline Box( "Partition for " || ycols[1] )][Table Box( 1 )] << Get As matrix;
If(
N Items( vcols ) == 1,
dt_results:"Training RSquare"n[i] = RSq_mat[1];
dt_results:"Training RASE"n[i] = RSq_mat[2];
dt_results:"Training N"n[i] = RSq_mat[3];
dt_results:"Validation RSquare"n[i] = RSq_mat[2, 1];
dt_results:"Validation RASE"n[i] = RSq_mat[2, 2];
dt_results:"Validation N"n[i] = RSq_mat[2, 3];,
N Items( vcols ) == 0 & Is Missing( PartVP ) == 0,
dt_results:"Training RSquare"n[i] = RSq_mat[1];
dt_results:"Training RASE"n[i] = RSq_mat[2];
dt_results:"Training N"n[i] = RSq_mat[3];
dt_results:"Validation RSquare"n[i] = RSq_mat[2, 1];
dt_results:"Validation RASE"n[i] = RSq_mat[2, 2];
dt_results:"Validation N"n[i] = RSq_mat[2, 3];,
N Items( vcols ) == 0,
dt_results:"Training RSquare"n[i] = RSq_mat[1];
dt_results:"Training RASE"n[i] = RSq_mat[2];
dt_results:"Training N"n[i] = RSq_mat[3];
);
Report << CloseWindow;
);
Try(
neg_rows = dt_results << Get Rows Where( :"RSquare Diff"n < 0 | :"Training RSquare"n < 0 | :"Validation RSquare"n < 0 );
dt_results << Select Rows( neg_rows ) << Markers( 11 );
dt_results << Clear Select;
);
Part_TB;
);
AutoPart = Expr(
Partwin = New Window( "Select Columns",
<<Return Result,
<<On Validate,
Border Box( Left( 3 ), Top( 2 ),
Outline Box( "JSL to help with Partitioning",
<<Set Font Size( 12 ),
V List Box(
H List Box(
Panel Box( "Select Columns",
V List Box( colListData = Col List Box( dtchosen, All, Grouped, width( lbWidth ), nLines( 12 ) ) ),
Spacer Box( Size( 0, 16 ) )
),
Panel Box( "Cast Selected Columns into Roles",
Lineup Box( N Col( 2 ), Spacing( 3, 2 ),
Button Box( "Y, Response", colListY << Append( colListData << GetSelected ) ),
colListY = Col List Box( width( lbWidth ), nLines( 4 ), Min Items( 1 ) ),
Button Box( "X, Factor", colListX << Append( colListData << GetSelected ) ),
colListX = Col List Box( width( lbWidth ), nLines( 4 ), Min Items( 1 ) ),
Button Box( "Weight", colListW << Append( colListData << GetSelected ) ),
colListW = Col List Box(
width( lbWidth ),
Max Selected( 1 ),
Max Items( 1 ),
nLines( 1 ),
<<Set Data Type( "Numeric" )
),
Button Box( "Freq", colListF << Append( colListData << GetSelected ) ),
colListF = Col List Box(
width( lbWidth ),
Max Selected( 1 ),
Max Items( 1 ),
nLines( 1 ),
<<Set Data Type( "Numeric" )
),
Button Box( "Validation", colListV << Append( colListData << GetSelected ) ),
colListV = Col List Box(
width( lbWidth ),
nLines( 1 ),
Max Selected( 1 ),
Max Items( 1 ),
<<Set Data Type( "Numeric" ),
)
)
),
Panel Box( "Action",
Lineup Box( N Col( 1 ),
Button Box( "OK",
recallRoles;
max_sp = max_sp_input << get;
partVP = partVP_input << Get;
ycols = ColListY << Get Items;
xcols = ColListX << Get Items;
Wcols = ColListX << Get Items;
Fcols = ColListF << Get Items;
vcols = ColListV << Get items;
Part;
Partwin << Close Window;
),
Button Box( "Cancel", Partwin << Close Window ),
Spacer Box( Size( 0, 22 ) ),
Button Box( "Remove",
colListY << RemoveSelected;
colListX << RemoveSelected;
colListW << RemoveSelected;
colListF << RemoveSelected;
colListV << RemoveSelected;
),
Button Box( "Recall",
clearRoles;
Try(
colListY << Append( ::ycolRecall );
colListX << Append( ::xcolRecall );
colListW << Append( ::WcolRecall );
colListF << Append( ::FcolRecall );
colListV << Append( ::vcolRecall );
max_sp_input << Set( ::max_spRecall );
partVP_input << Set( ::partVPRecall );
);
),
Button Box( "Relaunch",
FirstWin;
Try( Close( dt_results, No Save ) );
Partwin << Close Window;
),
Spacer Box( Size( 0, 22 ) ),
Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
)
)
),
H List Box(
Panel Box( "Max partition splits", max_sp_input = Number Edit Box( 20, 6 ) ),
Panel Box( "Validation Portion (if no validation column)", partVP_input = Number Edit Box( ., 6 ) )
)
)
)
)
)
);
//Interactive dialogue window to start Generalized Tuning
FirstWin = Expr(
AutoTuneDlg1 = New Window( "Partioning Automation",
<<Return Result,
<<On Validate,
Border Box( Left( 3 ), top( 2 ),
Outline Box( "Something to help simplify partitioning",
<<Set Font Size( 12 ),
H List Box(
V List Box(
Panel Box( "Select Data Table",
H List Box( Button Box( "Select Data Table", choose_data_table ), Spacer Box( Size( 100, 0 ) ) )
),
),
Panel Box( "Action",
Lineup Box( N Col( 1 ),
Button Box( "OK",
recallRolesS1;
AutoPart;
AutoTuneDlg1 << Close Window;
),
Button Box( "Cancel", AutoTuneDlg1 << Close Window ),
Spacer Box( Size( 0, 25 ) ),
Button Box( "Recall", Try( dtchosen = ::dtchosenRecall ) ),
Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
)
)
)
)
)
)
);
FirstWin;