ellisp / forecastHybrid

Convenient functions for ensemble forecasts in R combining approaches from the {forecast} package
GNU General Public License v3.0
79 stars 23 forks source link

ts object not recognised in hybridModel of forecastHybrid package #77

Closed nikitagupta55 closed 7 years ago

nikitagupta55 commented 7 years ago

Data is something like this:

df <- tribble(
    ~y,~timestamp

    18.74682, 1500256800,

    19.00424, 1500260400,

    18.86993, 1500264000,

    18.74960, 1500267600,

    18.99854, 1500271200,

    18.85443, 1500274800,

    18.78031, 1500278400,

    18.97948, 1500282000,

    18.86576, 1500285600,

    18.55633, 1500289200,

    18.79052, 1500292800,

    18.74790, 1500296400,

    18.62743, 1500300000,

    19.04696, 1500303600,

    18.97851, 1500307200,

    18.70956, 1500310800,

    18.92302, 1500314400,

    18.91465, 1500318000,

    18.61556, 1500321600,

    19.03535, 1500325200 )

I'm trying to apply hybridModel on timeseries data to perform ensemble.Below is my code:

library(tidyquant)

library(forecast)

library(timetk)

library(sweep)

library(forecastHybrid)

df <- mutate(df, timestamp = as_datetime(timestamp))

tk_ts_df <- tk_ts(df, start = 1, freq = 3600, silent = TRUE)

fit <- hybridModel(tk_ts_df)

On fitting timeseries object tk_ts_df (ts object) to hybridModel; it's giving error : "The time series must be numeric and may not be a matrix or dataframe object."

But on link: https://cran.r-project.org/web/packages/forecastHybrid/vignettes/forecastHybrid.html

It's clearly mentioned : The workhorse function of the package is hybridModel(), a function that combines several component models from the “forecast” package. At a minimum, the user must supply a ts or numeric vector for y

Please suggest what I'm doing wrong.

dashaub commented 7 years ago

Can't run your example right now, but it looks like the problem is probably the tk_ts_df object: the input timeseries in hybridModel() should only be a ts object or a numeric vector. Try converting it to one of these.

nikitagupta55 commented 7 years ago

@dashaub It doesn't support timetk object ? Like other models (arima,hw) from forecast package do?

dashaub commented 7 years ago

If the base models arima, ets, etc support it, it should be a pretty easy fix to add support. I'll take a look and let you know.

nikitagupta55 commented 7 years ago

@dashaub Base models completely supports it. Also I believe that, hybridModel will also not support sweep package. If you could make that work too, it will be great.

For eg: I use sweep to make my forecast result tidy like below:

forecast <- forecast(fit, h = 10, level = c(70,85)) forecast_tidy <- sw_sweep(forecast , fitted = TRUE , timetk_idx = TRUE)

This works completely fine on ARIMA, ets etc

dashaub commented 7 years ago

Fixed on Github now, should be up on next CRAN release in about a month.

nikitagupta55 commented 7 years ago

Awesome, will this support sweep also?

dashaub commented 7 years ago

Yes, both should work. Try it out and confirm if you like

devtools::install_github("ellisp/forecastHybrid/pkg")
nikitagupta55 commented 7 years ago

@dashaub It works completely fine now as expected. Thanks. Would you mind putting some relevant answer here : https://stackoverflow.com/questions/45429069/ts-object-not-recognised-in-hybridmodel-of-forecasthybrid-package ; I asked this question on stackoverflow.

dashaub commented 7 years ago

done