Rev 89613 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/datasets/man/Nile.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2026 R Core Team% Distributed under GPL 2 or later\name{Nile}\docType{data}\alias{Nile}\title{Flow of the River Nile}\usage{Nile}\description{Measurements of the annual flow of the river Nile at Aswan (formerly\sQuote{\I{Assuan}}), 1871--1970, in \eqn{10^8 m^3},\dQuote{with apparent changepoint near 1898}\bibcitep{|R:Cobb:1978|table 1 on page 249}.}\format{A time series of length 100.}\source{\bibshow{R:Durbin+Koopman:2001}\crData was available from the book website, now archived at\url{https://web.archive.org/web/20020304222057/http://www.ssfpack.com/dkbook/}.}\references{\bibshow{*, R:Balke:1993}}\examples{require(stats); require(graphics)par(mfrow = c(2, 2))plot(Nile)acf(Nile)pacf(Nile)ar(Nile) # selects order 2cpgram(ar(Nile)$resid)par(mfrow = c(1, 1))arima(Nile, c(2, 0, 0))## Now consider missing values, following Durbin & KoopmanNileNA <- NileNileNA[c(21:40, 61:80)] <- NAarima(NileNA, c(2, 0, 0))plot(NileNA)pred <-predict(arima(window(NileNA, 1871, 1890), c(2, 0, 0)), n.ahead = 20)lines(pred$pred, lty = 3, col = "red")lines(pred$pred + 2*pred$se, lty = 2, col = "blue")lines(pred$pred - 2*pred$se, lty = 2, col = "blue")pred <-predict(arima(window(NileNA, 1871, 1930), c(2, 0, 0)), n.ahead = 20)lines(pred$pred, lty = 3, col = "red")lines(pred$pred + 2*pred$se, lty = 2, col = "blue")lines(pred$pred - 2*pred$se, lty = 2, col = "blue")## Structural time series modelspar(mfrow = c(3, 1))plot(Nile)## local level model(fit <- StructTS(Nile, type = "level"))lines(fitted(fit), lty = 2) # contemporaneous smoothinglines(tsSmooth(fit), lty = 2, col = 4) # fixed-interval smoothingplot(residuals(fit)); abline(h = 0, lty = 3)## local trend model(fit2 <- StructTS(Nile, type = "trend")) ## constant trend fittedpred <- predict(fit, n.ahead = 30)## with 50\% confidence intervalts.plot(Nile, pred$pred,pred$pred + 0.67*pred$se, pred$pred -0.67*pred$se)## Now consider missing valuesplot(NileNA)(fit3 <- StructTS(NileNA, type = "level"))lines(fitted(fit3), lty = 2)lines(tsSmooth(fit3), lty = 3)plot(residuals(fit3)); abline(h = 0, lty = 3)}\keyword{datasets}