在您之前的问题中:
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可以完全不同!