代码之家  ›  专栏  ›  技术社区  ›  Joe

时间序列建模(Arima模型拟合误差)

  •  0
  • Joe  · 技术社区  · 3 年前

    我试图将Arima模型拟合到我的数据中,但遇到了以下错误消息,有人知道我该如何修复吗。我认为这与我的df有关,但不确定如何将其更改为单变量

    密码

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

    错误消息

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

    数据片段(已作为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
    
    1 回复  |  直到 3 年前
        1
  •  1
  •   Zheyuan Li    3 年前

    在您之前的问题中: Setting the first column as an index ,我已经建议您可能需要一个“ts”对象。在那里复制我的代码:

    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)
    

    现在让我们做

    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
    

    你不能只做:

    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
    

    比较 x fake :

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

    有两件事 print() s可以完全不同!