O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To build an automated ARIMA model, follow these steps:

  1. Read the data. The file has monthly stock prices from Yahoo! Finance for Infosys between March 1999 and January 2015:
> infy <- read.csv("infy-monthly.csv")
  1. Create the time series object:
> infy.ts <- ts(infy$Adj.Close, start = c(1999,3),     frequency = 12) 
  1. Run the ARIMA model:
> infy.arima <- auto.arima(infy.ts) 
  1. Summary of the ARIMA model is obtained as follows:
> summary(infy.arima)Series: infy.ts ARIMA(2,1,1)(1,0,1)[12] Coefficients:          ar1 ar2 ma1 sar1 sma1      -0.7513 -0.0368 0.5580 -0.3977 0.4678s.e. 0.3945 0.1304 0.3881 0.8703 0.8476sigma^2 estimated as 4.687: log likelihood=-413.89AIC=839.79 AICc=840.25 BIC=859.27Training set error measures: ME RMSE MAE MPE MAPE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required