5

在将我的 ARIMA 拟合到数据时,我不断收到错误消息,“数据”必须是矢量类型,为“NULL”。

library(forecast)

foo <- read.csv("https://nofile.io/g/0qrJl41nhf3bQQFjBmM6JurzGJFQSioCTGEzZhWVl9zA1kXnAJsCsSsxN1ZN7F4D/data.csv/")

data <- data.frame(year, Car)
data <- ts(data[,2],start = c(1990,1),frequency = 1)

plot(data)
plot(diff(data),ylab='Differenced Car Usage')
plot(log10(data),ylab='Log (Car Usage)')
plot(diff(log10(data)),ylab='Differenced Log (Tractor Sales)')
par(mfrow = c(1,2))
acf(ts(diff(log10(data))),main='ACF Tractor Sales')
pacf(ts(diff(log10(data))),main='PACF Tractor Sales')

require(forecast)
ARIMAfit <- auto.arima(log10(data), approximation=FALSE,trace=FALSE)
summary(ARIMAfit)

par(mfrow = c(1,1))
pred <- predict(ARIMAfit, n.ahead = 3)

数组(x,c(长度(x),1L)中的错误,如果(!is.null(名称(x)))列表(名称(x),:“数据”必须是向量类型,为“空” '

我只是不明白我做错了什么,如果有人看到这个问题,我将不胜感激。谢谢-MF

4

1 回答 1

8
library(forecast)
foo <- read.table(file="data.csv", header=T, sep=",")
data <- ts(foo$Car,start = c(1990,1),frequency = 1)

# Use 'forecast' to get predition from the model estimated by 'auto.arima'
ARIMAfit1 <- auto.arima(log10(data), approximation=T, trace=FALSE, allowdrift=F)
summary(ARIMAfit1)
forecast(ARIMAfit1, h = 3)

#      Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
# 2017       1.415713 1.165870 1.665556 1.0336109 1.797815
# 2018       1.415713 1.128307 1.703119 0.9761635 1.855262
# 2019       1.415713 1.095115 1.736310 0.9254014 1.906024


# The same model estimated using 'arima'
# Here you can use 'predict'
ARIMAfit2 <- arima(log10(data), order=c(0,1,1))
summary(ARIMAfit2)
predict(ARIMAfit2, n.ahead=3)

# $pred
# Time Series:
# Start = 2017 
# End = 2019 
# Frequency = 1 
# [1] 1.415713 1.415713 1.415713
# $se
# Time Series:
# Start = 2017 
# End = 2019 
# Frequency = 1 
# [1] 0.1911677 0.2199090 0.2453055
于 2017-12-17T11:05:09.657 回答