Prathit
Prathit

Reputation: 87

Error in fitting a model using auto.arima

Whenever I try to fit a model using auto.arima I get an error

auto.arima can only handle univariate time series

But I have converted the data into time series. Can anyone help?

library(forecast)
sales = data.frame(
Year = c(2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018),
Qtr1 = c(2.32,4.36,8.74,16.24,37.04,47.79,51.03,74.47,74.78,78.29,77.32),
Qtr2 = c(1.7,3.79,8.75,18.65,35.06,37.43,43.72,61.17,51.19,50.76,52.22),
Qtr3 = c(0.72,5.21,8.40,20.34,26.03,31.24,35.20,47.53,40.40,41.03,41.30),
Qtr4 = c(6.89,7.37,14.1,17.07,26.91,33.8,39.27,48.05,45.51,46.68,46.89))
sales
plot(sales)

salests = ts(sales)
tsdisplay(salests)
arima_fit = auto.arima(salests,stepwise = FALSE, approximation = FALSE) ##ERROR 

a_f = forecast(arima_fit, h =8)    
plot(a_f)

Upvotes: 0

Views: 550

Answers (1)

Stephan Kolassa
Stephan Kolassa

Reputation: 8267

Your salests is a matrix containing five time series, one for each column. The first time series is called Year, then Qtr1 through Qtr4. This is probably not what you wanted.

Take your sales data, convert it into a matrix, drop the first column (which contains the years), transpose it, convert it into a vector and convert this into a time series:

salests <- ts(as.vector(t(as.matrix(sales)[,-1])),frequency=4,start=c(2008,1))

Upvotes: 1

Related Questions