config-i1 / smooth

The set of functions used for time series analysis and in forecasting.
89 stars 19 forks source link

Error in is.constant(y) #194

Closed Steviey closed 2 years ago

Steviey commented 2 years ago

R 4.0.5, smooth 3.1.5

I try the following code and get the error-msg. below:

liveData<-0
if(liveData<1){
    idx=120
    y<-rnorm(idx, mean=15, sd=5)
    x<-cbind(
        x1 =  rnorm(idx, mean=15, sd=5)
        ,x2 =  rnorm(idx, mean=15, sd=5)
        ,x3 =  rnorm(idx, mean=15, sd=5)
        ,x4 =  rnorm(idx, mean=15, sd=5)
        ,x5 =  rnorm(idx, mean=15, sd=5)
    )   
    data    <- data.frame(x=x,value=y,stringsAsFactors=F)
    data    <- data %>% dplyr::relocate(value)
}

myModel <- adam(data,"ANN",silent=TRUE,h=1,holdout=FALSE)

myPlot<-plot(forecast::forecast(myModel,h=10,interval="complete",nsim=100),main="Complete prediction interval")
print(myPlot)
View(myModel)
stop()

Error in is.constant(y) : 
  'list' object cannot be coerced to type 'double'
    3. +-forecast:::forecast.default(...)
 4. | \-forecast:::forecast.ts(object, ...)
 5. |   +-fabletools::forecast(...)
 6. |   \-forecast::ets(...)
 7. |     \-forecast::is.constant(y)
 8. \-(function () ...
 9.   \-lobstr::cst()
 10.      
config-i1 commented 2 years ago

Hi, This is because of the conflicting methods in the packages. I've submitted on CRAN the new version of greybox that is supposed to resolve this. Please, give it a try with the development versions of the package:

Steviey commented 2 years ago

Windows 7, greybox 1.0.5.41001, smooth 3.1.6.41004, R version 4.0.5

I get the same result with the versions above...


liveData<-0
if(liveData<1){
    idx=120
    y<-rnorm(idx, mean=15, sd=5)
    x<-cbind(
        x1 =  rnorm(idx, mean=15, sd=5)
        ,x2 =  rnorm(idx, mean=15, sd=5)
        ,x3 =  rnorm(idx, mean=15, sd=5)
        ,x4 =  rnorm(idx, mean=15, sd=5)
        ,x5 =  rnorm(idx, mean=15, sd=5)
    )   
    data    <- data.frame(x=x,value=y,stringsAsFactors=F)
    data    <- data %>% dplyr::relocate(value)
}

myModel <- adam(data,"ANN",silent=TRUE,h=1,holdout=FALSE)

myPlot<-plot(forecast::forecast(myModel,h=10,interval="complete",nsim=100),main="Complete prediction interval")
print(myPlot)
View(myModel)
stop()

Error in is.constant(y) : 
  'list' object cannot be coerced to type 'double'
config-i1 commented 2 years ago

Please, use:

myPlot<-plot(forecast(myModel,h=10,interval="complete",nsim=100),main="Complete prediction interval")

instead of forecast::forecast(myModel,...). If this doesn't work (which could mean that forecast package hasn't updated its imports) then use generics::forecast(myModel,...).

Steviey commented 2 years ago

Wow, generics works... image

One question: I like to customize the graph. ggplot+plotly allows zooming and panning. I can do this with smooth::es()...but I have no entries: 'lower' and 'upper' for the intervals in the adam-model to do so...Can you provide these?

image

config-i1 commented 2 years ago

In adam(), you need to produce forecasts, it does not generate intervals inside the function itself. So, it is closer to the style of forecast functions. Here is an example:

forecast(adamModel, h=h, interval="prediction", level=c(0.9,0.95))