gpt4 book ai didi

r - 在 R 中预测 Arima 模型返回奇怪的错误

转载 作者:行者123 更新时间:2023-12-04 16:48:55 25 4
gpt4 key购买 nike

我正在构建一个用于预测时间序列的 Shiny 应用程序。其中一个组成部分是使用 ARIMA 模型进行预测。用户指定历史数据的开始和结束,他们想在 ARIMA 模型中使用什么 p、d 和 q(如果他们不想使用 auto.arima),以及要预测的周期数。

auto.arima 以及我使用的其他预测方法(例如 Holt 和 Holt-Winters)一切正常。但是,当使用 arima() 创建具有自定义 p、d 和 q 的模型时,我从 forecast() 得到以下错误:

    Warning in .cbind.ts(list(e1, e2), c(deparse(substitute(e1))[1L],
deparse(substitute(e2))[1L]), : non-intersecting series

令我感到奇怪的是,当我在创建时间序列的函数中注释掉开始和结束参数时,一切运行正常....

这是我的代码的相关部分:

首先,读取包含第二列中要预测的值的指定 csv 文件,并准备要预测的那一列:

## Reads in the historical data from the uploaded file
readData <- reactive({
inFile <- input$inputFile
if (is.null(inFile))
return(NULL)
data <- read.csv(inFile$datapath)
data
})

## Returns the historical values to be used in forecasting
historical <- reactive({
data <- readData()
## Remove any commas and dollar signs, and convert to a number
data[,2] <- as.numeric(sub("\\,","",
sub("\\$","",data[,2])
)
)
data
})

创建时间序列:

      ## Converts the historical data to a time series
tsData <- reactive({
data <- historical()
data <- data[,2]
ts <- ts(data,
start=c(input$startYear, input$startTime),
end=c(input$endYear, input$endTime),
frequency = strtoi(input$frequency)
)
ts
})

Create the ARIMA model:
## Create an ARIMA model for forecasting
arimaModel <- reactive({
ts <- tsData()
if(input$arimaAuto){
fit <- auto.arima(ts)
}
else{
fit <- arima(ts,order=c(strtoi(input$arimaP),
strtoi(input$arimaD),
strtoi(input$arimaQ)))
}
fit
})

最后但同样重要的是,预测 - 抛出奇怪警告消息的部分:

  ## Creates an ARIMA model and returns a forecast based on that model.
arimaData <- reactive({
fit <- arimaModel()
print("Fit: ")
print(fit)
f <- forecast(fit#,
#h = input$forecast_periods,
#level=c(strtoi(input$confidence1), strtoi(input$confidence2))
)
print("Forecast:")
print(f)
f
})

在此先感谢您的帮助! :)

最佳答案

最后的问题是我使用的是 arima(...) 函数而不是 Arima(...)。原来它们是两个不同的函数。我遇到的问题是函数存储数据方式不同的结果。有关这方面的更多信息,请参阅 this post .好消息是,现在一切正常。

关于r - 在 R 中预测 Arima 模型返回奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30812088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com