christophsax / tempdisagg

Methods for Temporal Disaggregation and Interpolation of Time Series
http://cran.r-project.org/web/packages/tempdisagg
37 stars 5 forks source link

Number of forcasted periods is incorrect for super-annual frequencies. #40

Open christophsax opened 5 years ago

christophsax commented 5 years ago
library(tempdisagg)

For usual frequencies, things work like this:

lf = ts(1:4, start = 1989, freq = 1)
hf = ts(1:16, start = 1989, freq = 4)
predict(td(formula = lf~hf, conversion = 'first'))
#>      Qtr1 Qtr2 Qtr3 Qtr4
#> 1989 1.00 1.25 1.50 1.75
#> 1990 2.00 2.25 2.50 2.75
#> 1991 3.00 3.25 3.50 3.75
#> 1992 4.00 4.25 4.50 4.75

Howeever, for super-annual frequencies, this does not work:

lf = ts(1:4, start = 1989, freq = 1/2)
hf = ts(1:8, start = 1989, freq = 1)
predict(td(formula = lf~hf, conversion = 'first'))
#> High frequency series shorter than low frequency. Discarding low frequency after 1994.
#> Error in SubRegressionBased(y_l = y_l, X = X, hf = hf, lf = lf, lf.end = lf.end, : identical(dim(C)[2], dim(X)[1]) is not TRUE

Seems to be related to the following line in td:

n.fc <- as.integer(round((X.end - end) * f)) - fr + 1L

Which is calculated as 1 for the example above but should be 0.

This probably needs a few tests for the usual frequencies, as a change to the formula is likely to break stuff.

christophsax commented 4 years ago

Some experiments in https://github.com/christophsax/tempdisagg/tree/triennial