Some R commands for time series analysis ======================================== package: tseries Use the command setwd("C:/....") to set your working directory. x=read.table("m-unrate.txt") % Load data into R rate=x[,4] % Get the unemployment rate series ts.plot(rate) % Plot the time series. ** There are two commands to fit an ARMA models: ** ``arma'' and ``arima''. Each has its own features. ** For forecasting purpose, "arima" is better. ** ARMA command ** zt=diff(rate) % Take the first difference acf(zt,lag.max=15) % Compute the first 15 ACFS pacf(zt, lag.max=15) % Compute first 15 lags of PACFs m1=arma(zt, order=c(2,1)) % Fit an ARMA(2,1) model. summary(m1) % obtain fitted results names(m1) % provide a list of objects stored in "m1". ts.plot(m1$residuals) % obtain time plot of residuals plot(m1) % Obtain several plots. Click onthe plot window to see next plots. acf(m1$residuals,lag.max=15) % comput residuals ACFs Remark: ====== The command "arma" fits a constant term as a default option. You can include include.intercept=F to drop the constant term if needed. End of Remark. ============= ** ARIMA command ** You can use the command "arima" to fit the model as well. The order will be in the form order=c(p,d,q). If you use this command, then you can perform model checking via the command "tsdiag" and compute forecasts via the command "predict". For example, m3=arima(zt,order=c(2,0,1)) % fit an ARIMA(2,0,1) model to zt. tsdiag(m3) % model checking predict(m3,n.ahead=5) % produce 1- to 5-step ahead forecasts. Or more directly, m4=arima(rate,order=c(2,1,1)) tsdiag(m4) predict(m4,n.ahead=5)