Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-SARIMA fitted函数返回NULL_R_Arima - Fatal编程技术网

R-SARIMA fitted函数返回NULL

R-SARIMA fitted函数返回NULL,r,arima,R,Arima,作为我课程的一部分,我必须学习和预测亚特兰大机场的交通。对整个模型进行了验证。唯一的问题是,为了分析残差,我必须将拟合值绘制到实际值。 但是,我的SARIMA模型在使用拟合函数时返回一个对象NULL 数据集可以使用 你能告诉我问题出在哪里吗 #################################################### ##================================================## ## Traffic at Atlan

作为我课程的一部分,我必须学习和预测亚特兰大机场的交通。对整个模型进行了验证。唯一的问题是,为了分析残差,我必须将拟合值绘制到实际值。 但是,我的SARIMA模型在使用拟合函数时返回一个对象NULL

数据集可以使用

你能告诉我问题出在哪里吗

####################################################
##================================================##
##     Traffic at Atlanta Airport 2003-2019       ##
##================================================##
####################################################



# The purpose of this project is to forecast Atlanta Airport future traffic
# following the Box-Jenkins Methodology



## Import Data
#-------------
Atl.Traff <- read.csv2("AtlantaTraffic_2003-2019.csv")

## Convert the raw data into a time series
#-----------------------------------------
Atl.Traff.ts <- ts(Atl.Traff[,3], start=c(2003,1), frequency=12)


## Loading all the needed packages
#---------------------------------
library(tseries)
library(TSA)
library(zoo)
library(forecast)



#-----------------------------------
## Step 0 : Stationarization of data
#===================================


## Plot raw data time series
#---------------------------
plot.ts(Atl.Traff.ts, main="")
abline(reg=lm(Atl.Traff.ts~time(Atl.Traff.ts)), col="red") 
# There is a positive trend
plot(decompose(Atl.Traff.ts))
monthplot(Atl.Traff.ts)
# There is seasonality
acf(ts(Atl.Traff.ts,frequency=1))
pacf(ts(Atl.Traff.ts, frequency=1))
#The time series isn't stationary : positive trend, seasonality and 
#the series is not decaying fast to 0
adf.test(diff(Atl.Traff.ts), alternative = "stationary")

## Log transformation : reduce increasing variance
#-------------------------------------------------
l.Atl.Traff.ts <- log(Atl.Traff.ts)
plot(cbind(Atl.Traff.ts,l.Atl.Traff.ts), main='Traffic and log tansformation')
par(mfrow=c(1,2))
acf(ts(l.Atl.Traff.ts,frequency=1)) #The series doesn't decay fast to 0
pacf(ts(l.Atl.Traff.ts, frequency=1))
par(mfrow=c(1,1))
#We haven't reached stationarity but at least, it reduces the increasing variance effect


## Remove the trend : 1st order difference
#-----------------------------------------
dl.Atl.Traff.ts <- diff(l.Atl.Traff.ts,1) 
plot(dl.Atl.Traff.ts)
par(mfrow=c(1,2))
acf(ts(dl.Atl.Traff.ts, frequency=1), main="ACF : 1st order difference") 
pacf(ts(dl.Atl.Traff.ts, frequency=1), main="PACF : 1st order difference")
par(mfrow=c(1,1))

## Remove the seasonality : difference of order 12
#-------------------------------------------------
dl.Atl.Traff.ts_12 <- diff(dl.Atl.Traff.ts,12)
plot(dl.Atl.Traff.ts_12) #We observe some extreme values
par(mfrow=c(1,2))
acf(ts(dl.Atl.Traff.ts_12,frequency=1), main="ACF : difference of order 12")
pacf(ts(dl.Atl.Traff.ts_12, frequency=1), main="PACF : difference of order 12")
par(mfrow=c(1,1))


#--------------------------------------------------
## Step 1 : Determining ARMA order parameters (p,q)
#==================================================


# fit a multiplicative SARIMA on l.Atl.Traff.ts
# d=D=1: transformations performed on l.Atl.Traff.ts


# q, Q: MA part (ACF)
# q = 1
# Q = 1


# p,P: AR part (PACF)
# p=2 
# P=1



#----------------------------------
## Step 2 : Coefficients estimation
#==================================


## Build a model SARIMA(2,1,1)(1,1,1) s=12
#-----------------------------------------
model <- arima(l.Atl.Traff.ts, c(2,1,1), seasonal=list(order=c(1,1,1), period=12), method='ML')
model
#aic = -820.63


## Plot of the fitted value
#--------------------------
fit <- fitted(model)
plot.ts(cbind(l.Atl.Traff.ts,fit),plot.type='single',col=c('black','red'))
####################################################
##================================================##
##2003-2019年亚特兰大机场交通##
##================================================##
####################################################
#本项目的目的是预测亚特兰大机场未来的交通量
#遵循Box-Jenkins方法
##导入数据
#-------------

Atl.Traff好的,我刚刚找到了我问题的答案。TSA和预测库相互冲突。使用fitted功能时,您应该卸载TSA软件包。

请将此简化为一个最小的示例,并将输入数据正确地放在问题中,以便如果它从网络上下载,问题和答案仍然可用。尽可能减少代码和输入,同时提供足够的答案。使用
forcast::fitted
使用
forcast
而不是强制卸载