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>ScriptingRe: 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;
);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 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.