ARIMA 预测不断收到错误“数据"必须是向量类型,为“NULL" [英] ARIMA forecast keep getting error 'data' must be of a vector type, was 'NULL'

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

问题描述

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

库(预测)foo <- read.csv("https://nofile.io/g/0qrJl41nhf3bQQFjBmM6JurzGJFQSioCTGEzZhWVl9zA1kXnAJsCsSsxN1ZN7F4D/data.csv/")数据 <- data.frame(year, Car)数据 <- ts(data[,2],start = c(1990,1),frequency = 1)情节(数据)情节(差异(数据),ylab ='不同的汽车使用')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')需要(预测)ARIMAfit <- auto.arima(log10(data), approximation=FALSE,trace=FALSE)总结(ARIMAfit)par(mfrow = c(1,1))预测 <- 预测(ARIMAfit,n.ahead = 3)

<块引用>

数组错误(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :'data' 必须是向量类型,为 'NULL'

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

解决方案

library(forecast)foo <- read.table(file="data.csv", header=T, sep=",")数据 <- ts(foo$Car,start = c(1990,1),frequency = 1)# 使用'forecast'从'auto.arima'估计的模型中获得预测ARIMAfit1 <- auto.arima(log10(data), approximation=T, trace=FALSE,allowdrift=F)总结(ARIMAfit1)预测(ARIMAfit1,h = 3)# 点预测 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# 使用'arima'估计的相同模型# 在这里你可以使用'预测'ARIMAfit2 <- arima(log10(data), order=c(0,1,1))总结(ARIMAfit2)预测(ARIMAfit2,n.ahead=3)# $pred# 时间序列:# 开始 = 2017# 结束 = 2019# 频率 = 1# [1] 1.415713 1.415713 1.415713# $se# 时间序列:# 开始 = 2017# 结束 = 2019# 频率 = 1# [1] 0.1911677 0.2199090 0.2453055

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

解决方案

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天全站免登陆