cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Leo_Huang
Level I

plotting Time sequence forcast plot with graph builder(script)

 

I am wondering that I can keep the plot the time series predicted plot in graph builder or not. So that my supervisor can esaily read the trend in future then take plan immediately. The plot I already made have grouped x, so it should show several predicted line in one single plot.

 

The fowllowing script is the  time series predicted plot :

Time Series(
	X( :date ),
	Y( :CD ),
	ARIMA( 0, 1, 0 ),
	SendToReport(
	
		Dispatch(
			{"Model: I(1)  ", "Forecast"},
			"Time Series Predicted Graph",
			FrameBox,
			{Frame Size( 659, 144 )}
		)
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: plotting Time sequence forcast plot with graph builder(script)

Time series predictions do not seem as straight forward as other platforms.  To solve this I:

  1. Saved the time series script from the platform but then split it into separate Time Series() and Seasonal Arima() functions.
  2. Saved predictions into a new table
  3. Copied the script back to the original table
  4. Made graph

Time Series Prediction Formula.png

Names default to here( 1 );

//Open sample data
dt = Open( "$Sample_data/time series/co2.jmp" );

//Add rows to the original table
dt << Add rows( 12 );

//Calculate date for future rows
dt << New Column( "Year&Month Future",
	Numeric,
	"Continuous",
	Formula( 
		If( Is Missing( :Name( "Year&Month" ) ),
			Lag( :Name( "Year&Month Future" ), 1 ) + 1 / 24,
			:Name( "Year&Month" )
		)
	)
);

//Open time series
ts = dt << Time Series( Y( :CO2 ) );

//Add Arima
ar = ts << Seasonal Arima( 1, 1, 0, 0, 1, 1, 12 );

//Make a new table with predications
dtArima = ar << Save Prediction Formula;

//Graph with predictions in a separate data table
dtArima << Graph Builder(
	Size( 493, 303 ),
	Show Control Panel( 0 ),
	Variables( 
		X( :Row ), 
		Y( :Actual CO2 ), 
		Y( :Predicted CO2, Position( 1 ) ) ),
	Elements( 
		Points( X, Y( 1 ), 
		Legend( 19 ) ), 
		Line( X, Y( 2 ), 
		Legend( 20 ) ) )
);

//Or add predictions to original table:

//Copy the prediction formula and replace the column name, then save it to the original
//data table
Eval( Parse( 
	"dt << " || 
	Substitute( 
		Char((Column(dtArima, "CO2 Prediction Formula" ) << Get Script ) ), 
		":Actual ", 
		":" 
	) 
) );

/*
//Close temporary windows
ts << Close Window
dtArima << Close Window;
*/

//Graph with predictions in the original table
dt << Graph Builder(
	Size( 493, 303 ),
	Show Control Panel( 0 ),
	Variables( 
		X( :Name("Year&Month Future") ), 
		Y( :CO2 ), 
		Y( :CO2 Prediction Formula, Position( 1 ) ) ),
	Elements( 
		Points( X, Y( 1 ), 
		Legend( 19 ) ), 
		Line( X, Y( 2 ), 
		Legend( 20 ) ) )
);

View solution in original post

1 REPLY 1
ih
Super User (Alumni) ih
Super User (Alumni)

Re: plotting Time sequence forcast plot with graph builder(script)

Time series predictions do not seem as straight forward as other platforms.  To solve this I:

  1. Saved the time series script from the platform but then split it into separate Time Series() and Seasonal Arima() functions.
  2. Saved predictions into a new table
  3. Copied the script back to the original table
  4. Made graph

Time Series Prediction Formula.png

Names default to here( 1 );

//Open sample data
dt = Open( "$Sample_data/time series/co2.jmp" );

//Add rows to the original table
dt << Add rows( 12 );

//Calculate date for future rows
dt << New Column( "Year&Month Future",
	Numeric,
	"Continuous",
	Formula( 
		If( Is Missing( :Name( "Year&Month" ) ),
			Lag( :Name( "Year&Month Future" ), 1 ) + 1 / 24,
			:Name( "Year&Month" )
		)
	)
);

//Open time series
ts = dt << Time Series( Y( :CO2 ) );

//Add Arima
ar = ts << Seasonal Arima( 1, 1, 0, 0, 1, 1, 12 );

//Make a new table with predications
dtArima = ar << Save Prediction Formula;

//Graph with predictions in a separate data table
dtArima << Graph Builder(
	Size( 493, 303 ),
	Show Control Panel( 0 ),
	Variables( 
		X( :Row ), 
		Y( :Actual CO2 ), 
		Y( :Predicted CO2, Position( 1 ) ) ),
	Elements( 
		Points( X, Y( 1 ), 
		Legend( 19 ) ), 
		Line( X, Y( 2 ), 
		Legend( 20 ) ) )
);

//Or add predictions to original table:

//Copy the prediction formula and replace the column name, then save it to the original
//data table
Eval( Parse( 
	"dt << " || 
	Substitute( 
		Char((Column(dtArima, "CO2 Prediction Formula" ) << Get Script ) ), 
		":Actual ", 
		":" 
	) 
) );

/*
//Close temporary windows
ts << Close Window
dtArima << Close Window;
*/

//Graph with predictions in the original table
dt << Graph Builder(
	Size( 493, 303 ),
	Show Control Panel( 0 ),
	Variables( 
		X( :Name("Year&Month Future") ), 
		Y( :CO2 ), 
		Y( :CO2 Prediction Formula, Position( 1 ) ) ),
	Elements( 
		Points( X, Y( 1 ), 
		Legend( 19 ) ), 
		Line( X, Y( 2 ), 
		Legend( 20 ) ) )
);