The R Project SVN R

Rev

Rev 61153 | Rev 70729 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61153 Rev 61168
Line 26... Line 26...
26
  Cobb, G. W. (1978) The problem of the Nile: conditional solution to a
26
  Cobb, G. W. (1978) The problem of the Nile: conditional solution to a
27
  change-point problem.  \emph{Biometrika} \bold{65}, 243--51.
27
  change-point problem.  \emph{Biometrika} \bold{65}, 243--51.
28
}
28
}
29
\examples{
29
\examples{
30
require(stats); require(graphics)
30
require(stats); require(graphics)
31
par(mfrow = c(2,2))
31
par(mfrow = c(2, 2))
32
plot(Nile)
32
plot(Nile)
33
acf(Nile)
33
acf(Nile)
34
pacf(Nile)
34
pacf(Nile)
35
ar(Nile) # selects order 2
35
ar(Nile) # selects order 2
36
cpgram(ar(Nile)$resid)
36
cpgram(ar(Nile)$resid)
37
par(mfrow = c(1,1))
37
par(mfrow = c(1, 1))
38
arima(Nile, c(2, 0, 0))
38
arima(Nile, c(2, 0, 0))
39
 
39
 
40
## Now consider missing values, following Durbin & Koopman
40
## Now consider missing values, following Durbin & Koopman
41
NileNA <- Nile
41
NileNA <- Nile
42
NileNA[c(21:40, 61:80)] <- NA
42
NileNA[c(21:40, 61:80)] <- NA
43
arima(NileNA, c(2, 0, 0))
43
arima(NileNA, c(2, 0, 0))
44
plot(NileNA)
44
plot(NileNA)
45
pred <-
45
pred <-
46
   predict(arima(window(NileNA, 1871, 1890), c(2,0,0)), n.ahead = 20)
46
   predict(arima(window(NileNA, 1871, 1890), c(2, 0, 0)), n.ahead = 20)
47
lines(pred$pred, lty = 3, col = "red")
47
lines(pred$pred, lty = 3, col = "red")
48
lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
48
lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
49
lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
49
lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
50
pred <-
50
pred <-
51
   predict(arima(window(NileNA, 1871, 1930), c(2,0,0)), n.ahead = 20)
51
   predict(arima(window(NileNA, 1871, 1930), c(2, 0, 0)), n.ahead = 20)
52
lines(pred$pred, lty = 3, col = "red")
52
lines(pred$pred, lty = 3, col = "red")
53
lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
53
lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
54
lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
54
lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
55
 
55
 
56
## Structural time series models
56
## Structural time series models