ARIMA预测持续出现错误,“数据"必须为向量类型,为"NULL" [英] ARIMA forecast keep getting error 'data' must be of a vector type, was 'NULL'

查看:27
本文介绍了ARIMA预测持续出现错误,“数据"必须为向量类型,为"NULL"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将ARIMA拟合到数据时,我总是收到错误消息,数据"必须是向量类型,为"NULL".

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)

如果(!is.null(names(x)))list(names(x),:数据"必须是向量类型,为"NULL"

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'

我只是不明白我在做什么错,如果有人发现问题,我将不胜感激.谢谢-MF

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

推荐答案

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

这篇关于ARIMA预测持续出现错误,“数据"必须为向量类型,为"NULL"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆