如何在R中创建预测对象 [英] How to create a forecast object in R

查看:44
本文介绍了如何在R中创建预测对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个函数,该函数使用不同的预测方法(例如forecast::nnetarforecast::tbatsforecast::Arimaforecast::ets)来预测时间序列对象.
我知道forecastHybrid::hybridModel函数正在执行此操作,我只想创建更自定义的内容.因此,我现在返回包含result$meanresult$errorresult$fit的列表.我想使用精度或绘图功能,例如预测对象.有没有简单的方法可以做到这一点?还是太复杂了?

I have wrote a function that forecasts a time series object using different forecast methods like forecast::nnetar, forecast::tbats, forecast::Arima and forecast::ets.
I know that forecastHybrid::hybridModel function is doing this, I just wanted to create something more customized. So I am now returning a list with result$mean, result$error and result$fit. I want to use accuracy or plot function like forecast object. Is there a easy way to do that? or is it too complicated?

关于该函数,它使用一个ts对象,一个Arima模型(我通过进行差异处理并检查ACF-PACF图找到了该模型)以及要预测的地平线.它适用于nnetaretstbats和我的Arima模型.
它结合了拟合度和预测值,并创建了新的拟合值和预测值.
它返回一个列表对象,该列表对象的预测值为result$mean(在预测对象中也是如此),拟合值作为result$fit,错误值为result$error.
现在,有了该返回的对象,我就无法自动化一系列工作,例如具有准确性,绘制地块等.因此,如果可能的话,我想返回一个预测对象.就是这样.

About the function, it takes a ts object, an arima model-that I found by taking differences and checking ACF-PACF graphs- and a horizon to be forecasted. It applies nnetar, ets, tbats and my arima model.
It combines their fits and forecasts and create a new fit values and forecast values.
It returns a list object with forecasted values as result$mean (this is also same in forecast objects), fitted values as result$fit and errors as result$error.
Now with that returned object, I cant automate some series of works like having accuracy, making plots etc. So I want to return a forecast object if it is possible. that is what it is.

推荐答案

预测对象只是一个列表,其中包含一些项目,并具有预测"类.查看任何现有功能,以了解如何进行.这是一个非常简单的模板:

A forecast object is just a list containing a few items, and given a class "forecast". Look at any of the existing functions to see how to do it. Here is a very simple template:

myfun <- function(x, h, ...)
{
  # Compute some forecasts
  fc <- ....
  # Construct output list
  output <- list(mean=fc, x=x, ...)
  # Return with forecasting class
  return(structure(output, class='forecast'))
}

这篇关于如何在R中创建预测对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆