Home > OS >  Time series modelling (Arima model fitting error)
Time series modelling (Arima model fitting error)

Time:08-03

Im trying to fit a Arima model to my data but run into the following error message, does anyone know how I can fix this. I'm thinking its something to do with my df but unsure how i can change it to be univariate

code

mod1 = arima(df, order = c(1,0,0))

error message

Error in arima(df, order = c(1, 0, 0)) : only implemented for univariate time series

data snippet (already as a ts())

df
Time Series:
Start = 2 
End = 10 
Frequency = 1 
   year      Qtr1     Qtr2     Qtr3     Qtr4
 2 2005 13.950342 18.66797 21.73983 22.49755
 3 2006 17.116492 17.71430 20.50190 20.84159
 4 2007 18.918347 15.46002 17.87220 20.01701
 5 2008 18.508666 15.53064 16.06696 20.21658
 6 2009 16.255357 14.85671 15.28269 12.16084
 7 2010  8.889602 16.18042 19.74318 15.05649
 8 2011 15.130970 15.96652 17.79070 18.35192
 9 2012 15.793286 11.90334 16.37805 16.45706
10 2013 11.867353 17.07688 17.60640 18.81432

CodePudding user response:

In your previous question: Setting the first column as an index, I have already advised that you likely need a "ts" object. Copying my code over there:

dat <- structure(list(year = 2005:2011, Qtr1 = c(13.950342, 17.116492, 
18.918347, 18.508666, 16.255357, 8.889602, 15.13097), Qtr2 = c(18.66797, 
17.7143, 15.46002, 15.53064, 14.85671, 16.18042, 15.96652), Qtr3 = c(21.73983, 
20.5019, 17.8722, 16.06696, 15.28269, 19.74318, 17.7907), Qtr4 = c(22.49755, 
20.84159, 20.01701, 20.21658, 12.16084, 15.05649, 18.35192)), row.names = c(NA, 
-7L), class = "data.frame")

x <- ts(c(t(dat[-1])), start = c(2005, 1), frequency = 4)

Now let's do

arima(x, order = c(1,0,0))
#Call:
#arima(x = x, order = c(1, 0, 0))
#
#Coefficients:
#         ar1  intercept
#      0.4495    17.1316
#s.e.  0.1680     0.8696
#
#sigma^2 estimated as 6.78:  log likelihood = -66.64,  aic = 139.28

You can't just do:

df <- `row.names<-`(dat[-1], dat[[1]])
fake <- ts(df)

arima(fake, order = c(1,0,0))
#Error in arima(df, order = c(1, 0, 0)) : 
#  only implemented for univariate time series

Compare the difference between x and fake:

class(x)
#[1] "ts"

class(fake)
[1] "mts"    "ts"     "matrix"

Two things that print()s alike can be completely different!

  • Related