Script question for Rerun FormulasI asked this question on a prior post but that was a few weeks ago so it may not get noticed. I suspect this is an easy scripting question for this group. Below is a script (donated by frank) that successfully runs a Monte Carlo simulation for a Stepwise Regression. The only thing it did not do was to recalculate a number of columns where I have random numbers in formulas before conducting the Stepwise regression. The <
My unsuccessful attempt is line 19 in the script. Thanks.
Clear Globals();
Clear Log();
Names Default To Here( 1 );
//Define path in and out
Path_in = Pick File( "Select file" );
If( Directory Exists( "$Desktop\Fit_Stepwise" ),
,
Create Directory( "$Desktop\Fit_Stepwise" )
);
Path_out = "$Desktop\Fit_Stepwise\";
//Run Fit model and stepwise after open datatable
dt = Open( Path_in );
For( i = 1, i <= 1000, i++,
dt << Rerun Formulas;
ow = dt << Fit Model(
Y( :Y ),
Effects(
:Column 2 001,
:Column 2 002,
:Column 2 003,
:Column 2 004,
:Column 2 005,
:Column 2 006,
:Column 2 007,
:Column 2 008,
:Column 2 009,
:Column 2 010
),
Personality( "Stepwise" ),
Run,
SendToReport( Dispatch( {}, "Step History", OutlineBox, {Close( 1 )} ) )
);
dt_result = Report( ow )[Outline Box( "Stepwise Fit for Y" )][Outline Box( "Current Estimates" )][Table Box( 1 )] << Make Into Data Table;
dt_result << save( Path_out || Char( i ) || ".csv", "csv" );
ow << close window;
dt_result << Close Window;
);
dt << Close Window;
dt_result = Multiple File Import(
<<SET folder="">F\!"" ) > 0.05 ) ) << Delete Rows;
dt_result << Distribution( Stack( 1 ), Nominal Distribution( Column( :Parameter ), Horizontal Layout( 1 ), Vertical( 0 ) ) );</SET>Advanced Statistical ModelingRe: Script question for Rerun FormulasThank you, this is perfect. And thank you for being patient with me. Also, the help on Wait() is in help but not the scripting index, as you say.
Re: Script question for Rerun FormulasI'm not sure why the original script you had wouldn't update the values in the formula columns. You could maybe test this further by lowering the loop-count (use for example as max value) and adding Wait(1); for example after the <
Here is slightly modified script using the subset table you provided earlier. As you don't want to be more proficient with scripting, I won't go very deep on explaining how the functions here work, but see explanation below and comments in the script, I can also explain more if needed. The script provided here should:
- Loop over all columns found in dt and enable evaluation on them to allow recalculation on formula columns
- Run Fit Model 100 times and recalculate values in formula columns each time with <
- Will also use Show() to print Col Median() for one column to log. This will slow down the script execution, but should show that the values in column do change
- Create one result table with the results and close all unnecessary tables and windows
- After running loop has finished: hide and exclude rows with ProbF > 0.05 and then create distribution
Names Default To Here(1);
dt = Current Data Table();
//dt = Open("Subset of Test data.jmp");
dt << Show Window(0); // should provide slight speed improvement
For Each({col_name}, dt << get column names(String), Column(dt, col_name) << suppress eval(False));
get_stepwise = Expr(
dt << Rerun Formulas;
Show(Col Mean(As Column(dt, :Column 2 001))); //will slow down script execution, but shows that values in Column 2 001 should change
Show(Col Mean(As Column(dt, :Column 2 010)));
fm = dt << Fit Model(
Y(:Y),
Effects(
:Column 2 001, :Column 2 002, :Column 2 003, :Column 2 004, :Column 2 005, :Column 2 006, :Column 2 007, :Column 2 008, :Column 2 009,
:Column 2 010
),
Personality("Stepwise"),
Run,
SendToReport(Dispatch({}, "Step History", OutlineBox, {Close(1)})),
Invisible // should provide slight speed improvement
);
dt_result = Report(fm)[Outline Box("Stepwise Fit for Y")][Outline Box("Current Estimates")][Table Box(1)] << Make Into Data Table(invisible);
dt_result << New Column("Loop", Numeric, Continuous, <<SET each="" value="">F\!""n > 0.05) << Hide And Exclude(1) << Clear Select;
// plot distribution
dt_collector << Distribution(Stack(1), Nominal Distribution(Column(:Parameter), Horizontal Layout(1), Vertical(0)));</SET>
This script didn't seem to have no need for Wait(0) at least on my setup (fast PC, Windows 10 and JMP16.2). For me it seems like the formula values did get re-evaluated
Results:

Scripting index for Wait(), clicking Topic Help sometimes provides more info (in case of Wait() it does)

JMP Help - Wait(n) "Specifying Wait(0) enables one cycle of message processing."
Re: Script question for Rerun FormulasThe formulas in my table are not suppressed. Can you explain a bit more about the commands you are suggesting I add? I am almost completely ignorant about scripting (and don't really want to spend my time becoming more proficient - don't spend your energy telling me why I should - I am a special case in many ways). Do I put one column name inside the { } or put all 6 columns (separated by , or ;?)? Do I need to replace String with anything? And, do I list Column separately for the suppress eval (false) command?
Regarding wait() I tried that unsuccessfully, but I can't find any documentation in the scripting index on the wait() command.
Re: Script question for Rerun FormulasJust to make sure that column will be evaluated, add this before For loop (if you are using earlier version than JMP16 change For Each to For):
For Each({col_name}, dt << get column names(String),
Column(dt, col_name) << suppress eval(False)
);
In the table I opened the formula columns had evaluation suppressed, but it might just be safety feature with downloaded files.
If you have to add wait(0), you can go a bit excessive with to start with and almost add it after every row inside the for-loop. Usually there is no need for it in JMP, but there are some cases where it is required.
Re: Script question for Rerun FormulasI've attached the file. It looks like I inserted Rerun Formulas in the correct place but it isn't working. How and where does Wait go?
Re: Script question for Rerun FormulasRerun formulas should work, maybe you need to add wait(0) somewhere? Without seeing the datatable it is a bit difficult to test where the issue could be in (row count, column count, complicated formulas, random seed not changing for some reason).
With this simple example the values seem to update fine:
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(5),
New Column("Column1", Numeric, "Continuous", Format("Best", 12), Formula(Random Normal(1, 1))),
New Column("Column2", Numeric, "Continuous", Format("Best", 12), Formula(Random Normal(2, 1)))
);
For(i = 1, i <= 3, i++,
dt << Rerun Formulas;
Show(dt:Column1 << get as matrix);
Show(dt:Column2 << get as matrix);
fm = dt << Fit Model(
Y(:Column1),
Effects(:Column2),
Personality("Stepwise"),
Run,
SendToReport(Dispatch({}, "Step History", OutlineBox, {Close(1)}))
);
dt_result = Report(fm)[Outline Box("Stepwise Fit for Column1")][Outline Box("Current Estimates")][Table Box(1)] << Make Into Data Table;
fm << close window;
//dt_result << Close Window;
);