Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level III

## JSL script for save column in the Time Series

Hi,

I would like to know how to write in JSL script if I want to "save columns" for the first 2 models shown in the model comparison table. Referring to attachment 1 is showing the model comparison table for the first 2 models. Next, in attachment 2 is showing the "save columns" that I want it to open. I want to write both precedures above in script. Is there anyone that can show me?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level III

## Re: JSL script for save column in the Time Series

Of course. Below is my solution:

I put all the TFA as a temporary list into the main. Then Make the output result into data table. Since I just want to save column for the first TFA that appeared in the table, I use that TFA number to search back in the temporary list i created in the main and save that into save column.

``````main = {};
obj = dt << Time Series(
X( :Time ),
Y( :Shipment ),
Input List( :Capacity ),
Number of Autocorrelation Lags( 20 ),
Number of Forecast Periods( 11 ),
Input Series( :Capacity, Number of Autocorrelation Lags( 20 ), Number of Forecast Periods( 11 ) )
);
temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );
temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 0 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 2 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 2 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 0, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 2 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

datatable = Report( obj )[Table Box( 5 )] << make into data table;
datatable << Set Name( "table1" );
datatable << New Column( "Model2",
Numeric,
Continuous,
formula( Num( Regex( :Model, "\D", "", GLOBALREPLACE ) ) )
);
maxvalue = datatable[1, 11];
dt2 = main[maxvalue] << Save Columns;
dt2 << Set Name( "Result1" );
Column( dt2, 4 ) << Set Name( "Predicted_Shipment_1" );``````

5 REPLIES 5
Highlighted
Super User

## Re: JSL script for save column in the Time Series

Just send the << Save Columns command to the model object.  Here's the example in the scripting index.  Hope it helps!

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Time Series/Steel Shipments.jmp" );
obj = Time Series( Y( :Steel Shipments ) );
obj2 = obj << Arima( 1, 0, 0 );
obj2 << Save Columns;``````

Highlighted
Level III

## Re: JSL script for save column in the Time Series

Hi msharp,

Thank you for your reply but this is not what I want. It is ok because I have found the solution for it.

Thanks alot.

Highlighted
Super User

## Re: JSL script for save column in the Time Series

I am very pleased that you solved the issue yourself.  Would you post your solution so all of the user community can see how you solved it?

Jim
Highlighted
Level III

## Re: JSL script for save column in the Time Series

Of course. Below is my solution:

I put all the TFA as a temporary list into the main. Then Make the output result into data table. Since I just want to save column for the first TFA that appeared in the table, I use that TFA number to search back in the temporary list i created in the main and save that into save column.

``````main = {};
obj = dt << Time Series(
X( :Time ),
Y( :Shipment ),
Input List( :Capacity ),
Number of Autocorrelation Lags( 20 ),
Number of Forecast Periods( 11 ),
Input Series( :Capacity, Number of Autocorrelation Lags( 20 ), Number of Forecast Periods( 11 ) )
);
temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );
temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 0 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 0, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 1, 1, 2 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 1, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 1, 2 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 2, 0, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 2 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 1, 0, 0 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

temp = obj << Transfer Function(
Order( 2, 1, 1 ),
Seasonal( 0, 0, 0, 12 ),
:Capacity( Order( 0, 0, 1 ), Seasonal( 0, 0, 0, 12 ), Lag( 0 ) ),
Number of Forecast Periods( 11 ),

);
Insert Into( main, temp );

datatable = Report( obj )[Table Box( 5 )] << make into data table;
datatable << Set Name( "table1" );
datatable << New Column( "Model2",
Numeric,
Continuous,
formula( Num( Regex( :Model, "\D", "", GLOBALREPLACE ) ) )
);
maxvalue = datatable[1, 11];
dt2 = main[maxvalue] << Save Columns;
dt2 << Set Name( "Result1" );
Column( dt2, 4 ) << Set Name( "Predicted_Shipment_1" );``````

Highlighted
Level VI

## Re: JSL script for save column in the Time Series

I'm running across a similar issue, but instead of having many transfer functions to sort through and save only certain ones, I am running the ARIMA analysis on several columns in my source data table. This generates a model for each column. I then want to "save columns" from the Model:AR(1) hot button for each column, and do it via scripting.

I have tried the obj << Save Columns approach, which works, but only for the last column where the ARIMA was done. I need to do it for each one.

Unfortunately, when I save columns manually, the new data table doesn't come with a "source" script, so it's hard to figure out how to do this with JSL.

What I'm really after is only the predicted column from the model.

Any thoguhts/feedback on this would help.

Thanks!

Article Labels

There are no labels assigned to this post.