amvillegas / StMoMo

Stochastic Mortality Modelling
22 stars 6 forks source link

forecast.mrwd not working #19

Open mpascariu opened 6 years ago

mpascariu commented 6 years ago

I am getting errors when I try to forecast a mrwd model.

Example:

> # Thu Aug  9 14:12:10 2018 ------------------------------
> remove(list = ls())
> library(StMoMo)
> 
> mxt <- with(EWMaleData, Dxt/Ext)    # data
> R   <- mrwd(mxt)                    # fit model
> ls(R)
[1] "drift"     "fitted"    "residuals" "sigma"     "x" 

> FR  <- forecast(R, h = 10)          # forecast
Error in is.constant(y) : 
  (list) object cannot be coerced to type 'double'

Not sure what went wrong here.

mpascariu commented 6 years ago

This issue is related to imports/depends issue.

The mrwd.forecast() is not working with forecast method from forecast package. I will submit a fix soon.

kuojx94 commented 5 years ago

Hi,

Has this issue been solved? Or is there any way to overcome it?

krixxix commented 2 years ago

Hello, has anyone found a solution?

mpascariu commented 2 years ago

hi @krixxix, i wrote a fix for this issue some time ago in one of my packages. See the model.MRW() and predict.MRW() functions here: https://github.com/mpascariu/MortalityForecast/blob/master/R/model_MRW.R

Now, because a few years have passed i do not remember what exactly is going wrong with mrwd.forecast() and the forecast method. Probably something minor (data formatting inside the function, input object recognition...), however because of the coding approach in StMoMo it was easier/faster for me to make it work outside of the original package for my purposes.

I hope this helps.