Forecasting values along with corresponding years

45 views Asked by At

I have a sample data set (named as s3) in the following manner:

year  T_tc  P_tc  N_tc
1990  570  200    370
1991  490  100    390
1992  535  410    125
1993  495  270    225
1994  485  351    134
1995  430  330    100
1996  536  310    226
1997  546  246    300
1998  524  298    226
1999  493  286    207
2000  425  235    190
2001  585  258    327
2002  476  373    103
2003  452  225    227
2004  515  376    139
2005  509  381    128
2006  498  255    243
2007  462  321    141

I have followed the below steps for forecasting:

sample <- as.ts(s3$T_tc, start=1990, end=2000, order.by=s3$year, frequency=1)

library(forecast)
fit <- arima(sample$No_of_Test_Cases, order=c(1,0,1))
cast <- forecast(fit, n.ahead=4, level=c(80,85), lambda=TRUE, 
                 allow.multiplicative.trend=TRUE, find.frequency=TRUE, interval="year")
cast

Point Forecast     Lo 80    Hi 80    Lo 85    Hi 85    
19                 534.7275 490.3288 579.1262 484.8557 
20                 507.0437 450.7865 563.3010 443.8515 
21                 502.3010 445.7332 558.8687 438.7600 
22                 501.4885 444.9116 558.0653 437.9373 

But I need the output as:

Point Forecast    Lo 80     Hi 80    Lo 85    Hi 85    
2008               534.7275 490.3288 579.1262 484.8557 
2009               507.0437 450.7865 563.3010 443.8515 
2010               502.3010 445.7332 558.8687 438.7600 
2011               501.4885 444.9116 558.0653 437.9373

I need the forecasting values along with corresponding year.

1

There are 1 answers

0
Robert On

You can do this:

sample <- ts(s3$T_tc, start=1990)
plot(sample)
library(forecast)
fit <- Arima(sample, order=c(1,0,1))
cast <- forecast(fit, h=4, level=c(80,85), lambda=TRUE)
cast

> cast
     Point Forecast    Lo 80    Hi 80    Lo 85    Hi 85
2008       534.7275 490.3288 579.1262 484.8557 584.5993
2009       507.0437 450.7865 563.3010 443.8515 570.2359
2010       502.3010 445.7332 558.8687 438.7600 565.8420
2011       501.4885 444.9116 558.0653 437.9373 565.0397