robjhyndman / demography

demography package for R
https://pkg.robjhyndman.com/demography
73 stars 25 forks source link

Error returned when forecasting fdm object that was fitted with method = "M" #55

Open zjyap88 opened 10 months ago

zjyap88 commented 10 months ago

Hello, I encountered an error when I tried to forecast an fdm object with Japan mortality rates.

The code:

jpn <- hmd.mx("JPN", "username", "password", "Japan")
jpn2 <- extract.years(jpn, 1947:2004)
jpn2 <- extract.ages(jpn2, 0:100, combine.upper = TRUE)
fit <- fdm(jpn2, series = "total", method = "M")
fcast <- forecast(fit, 11)

which would return Error in fitted[, i] <- fitted(barima) : number of items to replace is not a multiple of replacement length

The same error was also encountered when using mortality rates of Austria, Belgium, Bulgaria, Hungary, Ireland and Spain that were cleaned or transformed to avoid 0 and NA values. However, I did not receive an error when using mortality rates of Australia, Italy, France and Scotland.

Any help to address these inconsistencies would be much appreciated. Thank you in advance.

robjhyndman commented 10 months ago

This appears to be a problem in ftsa::forecast.ftsm() rather than the demography package. Some weights are set to zero (due to you using method="M"), but then the ftsa package ignores that when computing fitted values. So the problem needs to be solved by the maintainer of the ftsa package. I will alert him.