graphics.off(); # shuts down all the open graphics plots objects(); # prints a list of all variables in memory remove(list=objects()); # sets objects() as a list, and then removes this list # of variables from memory options(scipen=20); # sets the decimal places in scientific notation library(stats); # loads the "stats" package, which contains the arima() routine. sink(file = "arma.out", append = FALSE, type = "output", split = TRUE); # creates a disk file of the terminal/screen output; type can be changed to # log inputted commands as well. myData <- read.table("data2.txt", header=TRUE); X1 <- as.matrix(myData$y); # loads a disk file of data series. the series should be in columns and include # a header. n=nrow(myData); myArma <- arima(X1, order = c(1,0,1), method=c("ML")); # runs a "canned" arima regression with p=1 and q=1, where d is the level # of differencing. print(myArma); print("ARMA Coefficients:"); print( coef(myArma)[1] ); print( coef(myArma)[2] ); print("Coefficient standard deviations:"); print( sqrt( vcov(myArma)[1,1] ) ); print( sqrt( vcov(myArma)[2,2] ) ); print("AIC"); print(myArma$aic); # prints out the estimates of the AR and MA coefficient mean and standard # deviations. print("Estimate of the innovations variance:"); print(myArma$sigma2); # prints out estimate of the mean of the ARMA residuals (innovations) variance. print("Coefficient t-stats:"); print( coef(myArma)[1] / sqrt(vcov(myArma)[1,1]) ); print( coef(myArma)[2] / sqrt(vcov(myArma)[2,2]) ); # prints out t-statistics. acf(myArma$residuals, 100); # shows an acf plot of the ARMA residuals out to 100 lags. print(Box.test(myArma$residuals, n/4, type = "Ljung-Box")); # runs a Ljung-box test on the ARMA residuals. print("Predicted values for time-series:"); print(predict(myArma, n.ahead=100, se.fit=TRUE)); # Calculate 10 step ahead forecasts for the level of the # series, and provide standard errors of prediction. forecast <- predict(myArma, n.ahead=100, se.fit=TRUE); plot.ts( forecast$pred ); sink(file = NULL); # closes the opened disk file opened above with sink.