r语言 - 平均值中的错误 - 未使用的参数


我在

使用预测包用 R 编写的函数时遇到问题。这是函数:

    generateARIMAForecasts <- function(inputTSDecompList, inputArimaOrder, fcstHrzn, cnst, drft){
  tmpSTL <- NULL;
  fcasting <- NULL;
  tsfcastList <- NULL;
  counter <- 1;
  while(counter <= length(inputTSDecompList)){
    #select the TS decompositions
    tmpSTL <- inputTSDecompList[counter]$TimeSeriesDecomposition;
    #add the lattice plot to the list of plots
    if(cnst == TRUE & drft == TRUE){
      fcasting <- forecast(tmpSTL, h=fcstHrzn, 
                           forecastfunction=function(x,h,level, ...){
                           fit <- Arima(x, order=inputArimaOrder, include.constant = TRUE, include.drift = TRUE) 
                           return(forecast(fit,h=fcstHrzn,level=level, ...))});
    }
    fcastCoefs <- fcasting$model$coef;
    fcstValues <- fcasting;
    fcastSummary <- summary(fcasting);
    #add the forecast results to the forecast list
    tsfcastList[[counter]] <- list(FinancialInstitution=LVTSFITimeSeriesList[counter]$LVTSFITimeSeriesList$FinancialInstitution, 
                             ForecastCoefficients=fcastCoefs,
                             ForecastedSeries=fcstValues,
                             ForecastSummary=fcastSummary);
    counter <- counter+1;
  }
  return(tsfcastList); 
}

该函数获取 STL 分解序列的列表,并为输入列表中的每个单独的 stl 分解时间序列生成 Arima 预测。我已经通过对单个元素进行硬编码来手动运行预测生成,并且可以工作。但是当我尝试使用该函数执行此操作时,出现以下错误

均值中的错误(对象, h = h, 水平 = 水平, 风扇 = 风扇, lambda

= lambda, : 未使用的参数 (预测函数 = 函数 (x, h, level, ...) { fit <- Arima(x, order = inputArimaOrder, include.constant = TRUE, include.drift = TRUE) return(forecast(fit, h = fcstHrzn, level = level, ...)) }) 另外:有 50 个或更多警告(使用 warnings() 查看前 50 个)

有人可以建议吗?

嗨,在

RStudio 控制台中手动调试每一行几个小时后,我发现问题是我的电话

tmpSTL <- inputTSDecompList[counter]$TimeSeriesDecomposition;

这返回了 NULL,因为我使用

tsDecomList[[counter]] <- list(FinancialInstitution=inputTSList[counter]$LVTSFITimeSeriesList$FinancialInstitution, TimeSeriesDecomposition=tsDecom);

所以我应该打电话

tmpSTL <- inputTSDecompList[[counter]]$TimeSeriesDecomposition;

最新更新