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

Negative values in final series #34

Closed christophsax closed 5 years ago

christophsax commented 5 years ago

From Alexei:

library(tempdisagg)
# despite the fact that monthly sales pattern is represented in positive values
# as well as quarterly sales,
# for some reasons td() returns negative sales volume
#
detrended2 <- ts( c(19.99391, 10.49304, 26.99217,
                    17.49130, 15.99043, 26.98957, 19.98870, 19.98783,
                    10.98696, 19.98609, 19.98522, 15.98435, 19.99391,
                    10.49304, 26.99217, 17.49130, 15.99043, 26.98957,
                    19.98870, 19.98783, 10.98696, 19.98609, 19.98522,
                    15.98435), frequency =12)
detrended2
vipp <- ts( c(100, 1000, 2000,  500, 100,  300,  500,  700), frequency=4)
vipp
x <- td( vipp ~ detrended2,  conversion = "sum")
x$values # ???
christophsax commented 5 years ago

library(tempdisagg)
detrended2 <- ts( c(19.99391, 10.49304, 26.99217,
                    17.49130, 15.99043, 26.98957, 19.98870, 19.98783,
                    10.98696, 19.98609, 19.98522, 15.98435, 19.99391,
                    10.49304, 26.99217, 17.49130, 15.99043, 26.98957,
                    19.98870, 19.98783, 10.98696, 19.98609, 19.98522,
                    15.98435), frequency =12)
vipp <- ts( c(100, 1000, 2000,  500, 100,  300,  500,  700), frequency=4)
x <- td(vipp ~ detrended2,  conversion = "sum")
summary(x)
#> 
#> Call:
#> td(formula = vipp ~ detrended2, conversion = "sum")
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -499.00 -449.86  -99.24  197.94 1001.00 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)  1504.03    1021.03   1.473    0.191
#> detrended2    -68.93      54.27  -1.270    0.251
#> 
#> 'chow-lin-maxlog' disaggregation with 'sum' conversion
#> 8 low-freq. obs. converted to 24 high-freq. obs.
#> Adjusted R-squared: 0.08057  AR1-Parameter: 0.4418

As you can see from the summary, detrended2 has negative but insignificant coefficient. This means your final series has and inverted pattern of your indicator.

library(tsbox)
ts_plot(ts_scale(ts_c(predict(x), detrended2)))

This is is because the defaul "chow-lin-maxlog" method estimates the relationship between the two series as being negative. If you have a strong prior that there is positive relationship between the indictor and your final series, use "denton-cholette". With all the defaults, it ensures that the percentage changes of your final series are as closely as possible to those of your series (while ensuring the aggregates are the same in vipp).

x1 <- td(vipp ~ 0 + detrended2, method = "denton-cholette", conversion = "sum")
plot(predict(x1))

This probably leads to a final series that is more in line with your expectations. But keep in mind that the assumption of a positive relationship is at odds with the data!

Created on 2019-04-11 by the reprex package (v0.2.1)

marketresearchru commented 5 years ago

Thank you for digging into, Christoph.