From ripley@stats.ox.ac.uk  Fri Nov 29 16:34:03 2002
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Fri Nov 29 16:34:03 2002
Subject: [Rd] Prediction from arima() object (library ts) (PR#2305)
In-Reply-To: <200211181412.PAA28853@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.31.0211291529490.16287-100000@gannet.stats>

Your `manual' code is misguided: I don't think you understand ARIMA
processes.

Read the help page more carefully, including the parameter `include.mean'.
If you use the correct differenced model, you will verify that arima is
working correctly.

Please don't report bugs unless you are sure you understand your own email
address!

On Mon, 18 Nov 2002 mcrae_allan@hotmial.com wrote:
                                ^^^^^^^  sic!
> 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))

That line is incorrect.

> 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")
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Prediction from arima() object (library ts) (PR#2305)
ripley@stats.ox.ac.uk