I’m looking to build a copy of this model effects dialog from fit model:
Goal is to build a script that will read in this effects expression from the model script that DOE saves in the table, allow people to tweak the effect expression and then run some analysis using fit model with the new effects expression.
If you run the dialog in below script, you will see that it reads in the effects expression from the model script stored in the table. Puts that in the list box that resembles Fit Model, allows you to tweak it and then when you hit ok it attempts to parse the listbox into a new effects expression and start a custom fit model dialog with that new expression.
The problem/difference is in the special name column: in the original expression it is stored as :name(“Height-”) but when retrieving that expression from the list box, it is stored as “Height-” which becomes a incomplete mathematical operation instead of a column name. So how do I apply the special column name rules to items from this list box? The same applies to crossed and nested terms with the special name column.
dt=Open("$SAMPLE_DATA/Big Class.jmp");
dt:height << Set Name( "Height-" );
FitModelScript = dt << Get table variable( "Fit Model" );
i = 1;
try(
While( !Is Empty( arg_i = Arg( parse(FitModelScript), i ) ),
If( Starts With( Char( Name Expr( arg_i ) ), "Effects" ),
EffectsExpr = Name Expr( arg_i );
Break();
,
i++
)
);
);
New Window( "Test",
Border Box( Left( 3 ), top( 2 ),
v list box(
H List Box(
Panel Box( "Select Columns",
v list box(
colListData = Col list box( All, width( 253 ), grouped, nLines( 20 ) ),
Spacer box(size(1,2))
)
),
Panel Box( "Cast Selected Columns into Roles",
Lineup Box( N Col( 2 ), Spacing( 3 ),
Button Box( "Response columns", colListYbox << Append( colListData << GetSelected ) ),
colListYbox = Col List Box( width( 200 ), nLines( 20 ), numeric, MinItems( 1 ) ),
)
),
Panel Box( "Model effects",
H List Box(
V List Box(
Button Box( "Main", LB << Append( colListData << GetSelected ) ),
Button Box( "Interact",
SelectedColumns = colListData << GetSelected();
For( i = 1, i <= N Items( SelectedColumns ), i++,
For( k = 1, k <= N Items( SelectedColumns ) - i, k++,
LB << Append( concat(SelectedColumns[i], " * ", SelectedColumns[i + k] ) )
)
);
),
Button Box( "Quadratic",
SelectedColumns = colListData << GetSelected();
For( i = 1, i <= N Items( SelectedColumns ), i++,
LB << Append( concat(SelectedColumns[i], " * ", SelectedColumns[i] ) )
);
),
Button Box( "Nest",
colListX = colListData << GetSelected();
For( i = 1, i <= N Items( colListX ), i++,
If(Column(colListX[i]) << Get Modeling Type() != "Nominal",
New window("Error",<<modal,Text box("Nested factors need to be column type Nominal. Colum: " || colListX[i] ));
Remove from(colListX, i);
);
);
MainNest = LB << get selected();
For( i = 1, i <= N Items( MainNest ), i++,
If(Column(MainNest[i]) << Get Modeling Type() != "Nominal",
New window("Error",<<modal,Text box("Nested factors need to be column type Nominal. Colum: " || MainNest[i] ));
Remove from(MainNest, i);
);
);
If(N items(colListX)>0,
For( i = 1, i <= N Items( MainNest ), i++,
If(Contains(colListX, MainNest[i])==0,
LB << Append(concat(MainNest[i], "[", concat items(colListX, ", "), "]"));
LB << Remove Item(contains(LB << Get items( ),MainNest[i]));
,
New window("Error", <<modal, Text box("Cannot nest column into itself, select different columns only. Column: " || MainNest[i]))
);
);
);
),
Button Box( "Remove", LB << Remove Selected( ) ),
Button Box("Reset",
LB << Remove All();
try(For( i = 1, i <= N Arg( EffectsExpr ), i++,
LB << Append( Char( Arg( parse(substitute(char(eval expr(EffectsExpr)), expr(":"),expr(""))), i ) ) )
))
),
),
LB = List Box( {}, nlines( 23 ) ),
Try(For( i = 1, i <= N Arg( EffectsExpr ), i++,
LB << Append( Char( Arg( parse(substitute(char(eval expr(EffectsExpr)), expr(":"),expr(""))), i ) ) )
))
)
),
Panel Box( "Actions",
Lineup Box( N Col( 1 ),
Button Box( "OK",
ResponseColumns = colListYbox << get items();
newEffectsExpr = Concat Items(LB << GetItems, ", ");
jsl = evalinsert("\[
try(FitModelDialogWindow << closewindow());
FitModelDialogWindow = Fit Model(
invisible,
Y( ^ResponseColumns^ ),
Effects( ^newEffectsExpr^ ),
Keep dialog open( 1 ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" )
);
]\");
eval(parse(jsl));
)
)
),
)
)
)
)