rjdverse / rjdemetra

R interface to JDemetra+ v 2.x
https://rjdverse.github.io/rjdemetra
52 stars 16 forks source link

Series after seas. adjustment differs from original #69

Closed AlexanderBae closed 4 years ago

AlexanderBae commented 4 years ago

Hi! I have a problem with seasonally adjusting several time series. In particular after adjusting "original" series stored in m$decomposition$components[, 'y_cmp' ] has different values for some periods than the original one. I used tramoseats function with following parameters:

tsspec<-tramoseats_spec(spec ="RSA3", estimate.to = "2019-06-30")

m<-tramoseats(var, spec = tsspec, userdefined = NULL)

Could you please help mi to fix my issue?

AQLT commented 4 years ago

Hi, This is normal: for the decomposition, the raw time-series is corrected for trading days and outliers. The "y_cmp" time series corresponds corresponds to this "linearized" series. You can find more details here: https://jdemetradocumentation.github.io/JDemetra-documentation/pages/theory/SA_lin%20—%20kopia.html. Below a simple example with no trading day adjustment and with only one additive outlier in october 2009. You can notice that the only difference with the "original" series occurs in october 2009 and it is equal to the coefficient of the outlier.

library(RJDemetra)
tsspec< - tramoseats_spec(spec = "RSA0",
                        usrdef.outliersEnabled = TRUE,
                        usrdef.outliersType = "AO",
                        usrdef.outliersDate = "2009-10-01")
m <- tramoseats(ipi_c_eu[,  "FR"], spec = tsspec, userdefined = NULL)
m$regarima
#> y = regression model + arima (0, 1, 1, 0, 1, 1)
#> Log-transformation: no
#> Coefficients:
#>           Estimate Std. Error
#> Theta(1)   -0.3783      0.052
#> BTheta(1)  -0.5815      0.047
#> 
#>               Estimate Std. Error
#> Mean          0.009894      0.030
#> AO (10-2009) -1.169685      1.463
#> 
#> 
#> Residual standard error: 1.969 on 318 degrees of freedom
#> Log likelihood = -679.7, aic =  1369 aicc =  1370, bic(corrected for length) = 1.426
round(ipi_c_eu[,"FR"] - m$decomposition$components[,"y_cmp"], 2)
#>        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
#> 1990  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1991  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1992  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1993  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1994  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1995  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1996  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1997  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1998  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 1999  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2000  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2001  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2002  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2003  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2004  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2005  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2006  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2007  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2008  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2009  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00 -1.17  0.00  0.00
#> 2010  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2011  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2012  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2013  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2014  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2015  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2016  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
#> 2017  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00

If you want to get the original series used by your model, the best solution is to use the function get_ts

get_ts(m)
#>        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
#> 1990  90.5  92.6 101.9  95.2  92.1 103.3  91.8  65.5  99.0 102.8  94.3  93.1
#> 1991  90.9  89.6  99.9  93.3  88.3 103.0  89.7  65.1  98.2 100.8  95.8  93.2
#> 1992  89.4  89.0  99.5  93.0  89.1 101.3  89.4  64.1  94.9  98.6  92.2  90.5
#> 1993  85.3  84.3  93.2  87.8  83.5  95.4  86.2  60.1  92.1  95.8  88.1  88.3
#> 1994  84.9  84.0  94.1  90.1  86.8 100.4  90.8  64.5  96.8 101.0  96.6  96.3
#> 1995  90.4  90.5 100.4  94.5  89.7 103.7  93.8  65.5  99.7 101.8  94.6  98.1
#> 1996  90.3  88.8 100.7  93.8  91.2 104.4  92.3  67.2 100.2 102.3  96.9  97.2
#> 1997  90.5  91.6 104.0  99.7  93.9 108.8  98.2  73.4 105.8 111.8 102.4 105.4
#> 1998  99.2  99.0 109.4 103.0 100.7 114.8 104.9  73.3 109.6 112.7 105.9 105.1
#> 1999 100.5  98.6 111.8 104.3 101.3 117.4 106.6  74.9 113.4 118.2 110.9 109.8
#> 2000 104.8 104.9 118.9 110.2 108.0 122.5 111.8  80.5 117.5 121.7 114.3 115.5
#> 2001 108.8 109.2 123.7 111.8 108.4 124.7 111.1  84.2 117.8 121.0 111.6 109.2
#> 2002 106.6 107.0 121.4 112.8 106.4 122.2 109.7  82.3 117.1 118.7 113.0 106.4
#> 2003 105.4 105.7 120.1 111.1 102.8 118.3 108.8  78.7 115.9 119.9 110.8 107.9
#> 2004 105.8 107.0 120.0 112.1 105.8 123.6 112.0  78.4 120.0 122.0 112.0 108.4
#> 2005 109.1 106.7 117.9 113.5 106.8 122.3 110.3  80.0 121.4 118.4 115.2 109.8
#> 2006 107.3 106.3 121.9 112.5 110.8 126.7 112.5  82.5 122.2 121.9 113.7 111.7
#> 2007 109.5 110.0 123.8 114.2 112.6 127.0 115.2  85.7 121.2 124.7 115.2 111.0
#> 2008 111.4 112.2 123.0 116.8 108.4 122.1 112.6  81.9 117.3 116.3 102.4  97.8
#> 2009  91.7  90.4 100.1  93.2  91.4 105.5  96.8  71.6 104.5 104.8  99.3  92.9
#> 2010  93.7  93.5 106.8  99.9  96.9 108.9 101.7  73.2 107.2 108.2 102.5  97.9
#> 2011 100.4 102.0 112.0 103.7 102.9 111.3 105.0  76.6 108.4 109.7 106.0  98.4
#> 2012  97.8  97.6 110.2 102.3  97.0 108.8 102.5  77.5 106.6 105.2  99.3  95.7
#> 2013  94.3  95.9 106.3 102.5  96.8 108.2 100.7  74.3 104.6 106.1 101.0  95.2
#> 2014  95.0  97.2 107.4 101.7  93.6 107.7 100.6  74.3 105.5 105.3  98.5  96.8
#> 2015  95.3  96.6 108.8 101.9  96.5 110.0  99.9  76.9 107.1 108.0 101.8  97.3
#> 2016  98.5  97.9 107.4 103.4  96.9 107.8  99.6  77.5 106.2 106.5 104.2  97.1
#> 2017  97.4  97.5 112.0 103.0 100.4 111.2 103.4  79.3 109.7 114.0 107.7 101.4

Created on 2019-12-13 by the reprex package (v0.3.0)