ARIMA时间序列预测在R中不起作用
我试图预测一个类似这样的时间序列(这是测试数据) 我从美国一个州得到数据。让我们这样说阿拉巴马州ARIMA时间序列预测在R中不起作用,r,forecasting,R,Forecasting,我试图预测一个类似这样的时间序列(这是测试数据) 我从美国一个州得到数据。让我们这样说阿拉巴马州 res <- subset(d, states == 'Alabama', select = c(levels, weeks)) aa <- auto.arima(tsn) forecast(aa) 然后我得到了最好的arima模型,就像这样 res <- subset(d, states == 'Alabama', select = c(levels, weeks)) a
res <- subset(d, states == 'Alabama', select = c(levels, weeks))
aa <- auto.arima(tsn)
forecast(aa)
然后我得到了最好的arima模型,就像这样
res <- subset(d, states == 'Alabama', select = c(levels, weeks))
aa <- auto.arima(tsn)
forecast(aa)
然后我尝试像这样使用预测函数
res <- subset(d, states == 'Alabama', select = c(levels, weeks))
aa <- auto.arima(tsn)
forecast(aa)
这就是我得到这个错误的时候
Error in forecast(aa) : unused argument (aa)
你知道怎么做预测吗
编辑以添加代码
这就是数据的样子
st URL WEBSITE al aln wk WEEKSEASON
Alabama http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-04-2008 40 2008-09
Alabama http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-11-2008 41 2008-09
Alaska http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-18-2008 42 2008-09
Alaska http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-25-2008 43 2008-09
library(forecast)
library(tseries)
#Extracts relevant data from the csv file
extract_data<-function(){
#open the file. NAME SHOULD BE CHANGED
sd <- read.csv(file="sdr.csv",head=TRUE,sep=",")
#Extracts the data from the ACTIVITY LEVEL column. Notice that the name of the column was changed on the file
#to 'al' to make the reference easier
lv_list <- sd$al
#Gets only the number from each value getting rid of the word "Level"
lvs <- sapply(strsplit(as.character(lv_list), " "), function(x) x[2])
#Gets the ACTIVITY LEVEL NAME. Column name was changed to 'aln' on the file
lvn_list <- sd$aln
#Gets the state. Column name was changed to 'st' on the file
st_list <- sd$st
#Gets the week. Column name was changed to 'wk' on the file
wlist <- sd$wk
#Divides the weeks data in month, day, year
wks <- sapply(strsplit(as.character(wlist), "-"), function(x) c(x[1], x[2], x[3]))
#Creates a data frame with the selected results. You can choose which data is needed.
result<-data.frame("states"=st_list,"levels"=lvs,"lvlnames"=lvn_list,"weeks"=wlist)
return(result)
}
forecast<-function(){
d=extract_data()
#Get data from each state
res <- subset(d, states == 'Alabama', select = c(levels, weeks))
#turn data into a time series
tsn = ts(res[[1]])
#Plot forecast data with ARIMA models (use differenciated data if needed)
aa <- auto.arima(tsn)
forecast(aa)
return(0) #return results
}
这就是代码的样子
st URL WEBSITE al aln wk WEEKSEASON
Alabama http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-04-2008 40 2008-09
Alabama http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-11-2008 41 2008-09
Alaska http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-18-2008 42 2008-09
Alaska http://adph.org/influenza/ Influenza Surveillance Level 1 Minimal Oct-25-2008 43 2008-09
library(forecast)
library(tseries)
#Extracts relevant data from the csv file
extract_data<-function(){
#open the file. NAME SHOULD BE CHANGED
sd <- read.csv(file="sdr.csv",head=TRUE,sep=",")
#Extracts the data from the ACTIVITY LEVEL column. Notice that the name of the column was changed on the file
#to 'al' to make the reference easier
lv_list <- sd$al
#Gets only the number from each value getting rid of the word "Level"
lvs <- sapply(strsplit(as.character(lv_list), " "), function(x) x[2])
#Gets the ACTIVITY LEVEL NAME. Column name was changed to 'aln' on the file
lvn_list <- sd$aln
#Gets the state. Column name was changed to 'st' on the file
st_list <- sd$st
#Gets the week. Column name was changed to 'wk' on the file
wlist <- sd$wk
#Divides the weeks data in month, day, year
wks <- sapply(strsplit(as.character(wlist), "-"), function(x) c(x[1], x[2], x[3]))
#Creates a data frame with the selected results. You can choose which data is needed.
result<-data.frame("states"=st_list,"levels"=lvs,"lvlnames"=lvn_list,"weeks"=wlist)
return(result)
}
forecast<-function(){
d=extract_data()
#Get data from each state
res <- subset(d, states == 'Alabama', select = c(levels, weeks))
#turn data into a time series
tsn = ts(res[[1]])
#Plot forecast data with ARIMA models (use differenciated data if needed)
aa <- auto.arima(tsn)
forecast(aa)
return(0) #return results
}
库(预测)
图书馆(tseries)
#从csv文件中提取相关数据
提取数据变量aa
是数据d
的模型估计值。使用aa
中的ARIMA(1,0,0)
并将其插入forecast.ARIMA
,如下所示
f <- forecast.Arima( d, order=c(1,0,0) )
f它实际上是通过将auto.arima的结果提供给forecast.arima函数来工作的。谢谢<代码>预测(auto.arima(ts(c(1,1,4,1,3,4)))
适合我。