ARIMA forecast keep getting error 'data' must be of a vector type, was 'NULL'

时光怂恿深爱的人放手 提交于 2021-02-19 05:01:25

问题


I keep getting an error when fitting my ARIMA to the data, 'data' must be of a vector type, was '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)

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), : 'data' must be of a vector type, was 'NULL'

I'm simply not understanding what I am doing wrong, I would appreciate any help if anyone sees the issue. Thanks -MF


回答1:


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


来源:https://stackoverflow.com/questions/47852567/arima-forecast-keep-getting-error-data-must-be-of-a-vector-type-was-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!