使用 auto.arima 拟合模型时出错
Error in fitting a model using auto.arima
每当我尝试使用 auto.arima 拟合模型时,我都会收到错误消息
auto.arima can only handle univariate time series
但是我已经把数据转换成时间序列了。
有人可以帮忙吗?
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)
您的 salests
是一个包含五个时间序列的矩阵,每列一个。第一个时间序列称为 Year
,然后是 Qtr1
到 Qtr4
。这可能不是你想要的。
获取您的 sales
数据,将其转换为矩阵,删除第一列(包含年份),转置它,将其转换为 vector
并将其转换为时间序列:
salests <- ts(as.vector(t(as.matrix(sales)[,-1])),frequency=4,start=c(2008,1))
每当我尝试使用 auto.arima 拟合模型时,我都会收到错误消息
auto.arima can only handle univariate time series
但是我已经把数据转换成时间序列了。 有人可以帮忙吗?
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)
您的 salests
是一个包含五个时间序列的矩阵,每列一个。第一个时间序列称为 Year
,然后是 Qtr1
到 Qtr4
。这可能不是你想要的。
获取您的 sales
数据,将其转换为矩阵,删除第一列(包含年份),转置它,将其转换为 vector
并将其转换为时间序列:
salests <- ts(as.vector(t(as.matrix(sales)[,-1])),frequency=4,start=c(2008,1))