I 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 <<Rerun Formulas command works when I manually click on the red arrow in the table and say Rerun Formulas, but in the script it doesn't do anything. Can someone help me get the formulas to Rerun before each iteration in the For loop?
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( Path_out ),
<<Set Name Filter( "*.*;" ),
<<Set Name Enable( 0 ),
<<Set Size Filter( {589, 589} ),
<<Set Size Enable( 0 ),
<<Set Date Filter( {3727681987.773, 3727682566.676} ),
<<Set Add File Name Column( 1 ),
<<Set Import Mode( "CSVData" ),
<<Set Charset( "Best Guess" ),
<<Set Stack Mode( "Stack Similar" ),
<<Set CSV Has Headers( 1 ),
<<Set CSV Allow Numeric( 1 ),
<<Set CSV First Header Line( 1 ),
<<Set CSV Number Of Header Lines( 1 ),
<<Set CSV First Data Line( 2 ),
<<Set CSV EOF Comma( 1 ),
<<Set CSV EOF Tab( 0 ),
<<Set CSV EOF Space( 0 ),
<<Set CSV EOF Spaces( 0 ),
<<Set CSV EOF Other( "" ),
<<Set CSV EOL CRLF( 1 ),
<<Set CSV EOL CR( 1 ),
<<Set CSV EOL LF( 1 ),
<<Set CSV EOL Semicolon( 0 ),
<<Set CSV EOL Other( "" ),
<<Set CSV Quote( "\!"" ),
<<Set CSV Escape( "" ),
<<Set Import Callback( Empty() )
) << Import Data;
dt_result << Row Selection( Select where( :Name( "\!"Prob>F\!"" ) > 0.05 ) ) << Delete Rows;
dt_result << Distribution( Stack( 1 ), Nominal Distribution( Column( :Parameter ), Horizontal Layout( 1 ), Vertical( 0 ) ) );