The R Project SVN R

Rev

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

Rev 59039 Rev 61168
Line 53... Line 53...
53
}
53
}
54
\examples{
54
\examples{
55
require(stats); require(graphics)
55
require(stats); require(graphics)
56
## work with pre-seatbelt period to identify a model, use logs
56
## work with pre-seatbelt period to identify a model, use logs
57
work <- window(log10(UKDriverDeaths), end = 1982+11/12)
57
work <- window(log10(UKDriverDeaths), end = 1982+11/12)
58
par(mfrow = c(3,1))
58
par(mfrow = c(3, 1))
59
plot(work); acf(work); pacf(work)
59
plot(work); acf(work); pacf(work)
60
par(mfrow = c(1,1))
60
par(mfrow = c(1, 1))
61
(fit <- arima(work, c(1,0,0), seasonal = list(order= c(1,0,0))))
61
(fit <- arima(work, c(1, 0, 0), seasonal = list(order = c(1, 0, 0))))
62
z <- predict(fit, n.ahead = 24)
62
z <- predict(fit, n.ahead = 24)
63
ts.plot(log10(UKDriverDeaths), z$pred, z$pred+2*z$se, z$pred-2*z$se,
63
ts.plot(log10(UKDriverDeaths), z$pred, z$pred+2*z$se, z$pred-2*z$se,
64
        lty = c(1,3,2,2), col = c("black", "red", "blue", "blue"))
64
        lty = c(1, 3, 2, 2), col = c("black", "red", "blue", "blue"))
65
 
65
 
66
## now see the effect of the explanatory variables
66
## now see the effect of the explanatory variables
67
X <- Seatbelts[, c("kms", "PetrolPrice", "law")]
67
X <- Seatbelts[, c("kms", "PetrolPrice", "law")]
68
X[, 1] <- log10(X[, 1]) - 4
68
X[, 1] <- log10(X[, 1]) - 4
69
arima(log10(Seatbelts[, "drivers"]), c(1,0,0),
69
arima(log10(Seatbelts[, "drivers"]), c(1, 0, 0),
70
      seasonal = list(order= c(1,0,0)), xreg = X)
70
      seasonal = list(order = c(1, 0, 0)), xreg = X)
71
}
71
}
72
\keyword{datasets}
72
\keyword{datasets}