[Rd] Prediction from arima() object (library ts) (PR#2305)

mcrae_allan@hotmial.com mcrae_allan@hotmial.com
Mon, 18 Nov 2002 15:12:24 +0100 (MET)


Full_Name: Allan McRae
Version: 1.6.0
OS: Win 2000 P
Submission from: (NULL) (129.215.190.229)


When using predict.Arima in library ts(), it appears differencing is only
accounted for in the first step of prediction and so any trend is not apparent
in the predictions.  The example shows the difference between the predictions of
an arima(1,1,1) model and the backtransformed predictions of an arima(1,0,1)
model fitted on the differenced data.

Example:

total <- c(750, 775, 971, 1099, 1344, 610, 910, 1056, 1589, 1006, 1469, 1598,
876, 1104, 1197, 1062, 1783, 1554, 1400, 1340, 1013, 1031, 1030, 860, 943, 1542,
1400, 1301, 1443, 1057, 1296, 710, 1038, 1447, 694, 889, 1459, 957, 1284, 1520,
1172, 1826, 1751, 1968, 933, 1409, 1889)

revtotal <- numeric(length(total))
for(i in 1:length(total))
	revtotal[i] <- total[length(total)-i+1]

# first model
m1 <- arima(revtotal, c(1,1,1))
pm1 <- predict(m1, n.ahead=15)
plot(1:47, y=revtotal, type="l", xlim=c(0,65))
lines(48:62, y=pm1$pred, col="red")

# second model - differencing done manually
drevtotal <- diff(revtotal)
m <- arima(drevtotal, c(1,0,1))
pm <- predict(m, n.ahead=15)
p <- numeric(15)
p[1] <- pm$pred[1] + revtotal[length(revtotal)]
for(i in 2:15)
	p[i] <- p[i-1] + pm$pred[i]
plot(1:47, y=revtotal, type="l", xlim=c(0,65))
lines(48:62, y=p, col="red")