rjdverse / rjdemetra

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

user defined calendars #83

Closed ClementFeltin closed 4 years ago

ClementFeltin commented 4 years ago

I am a new RJDemetra user, coming from the Demetra desktop world. While trying to replicate the processings I made on Demetra, I did not manage to use user defined calendars in my specifications : I used xml calendars, which is not supported, but I did not find the expected format in the documentation. Could you provide with an example ? Thanks !

AQLT commented 4 years ago

Hi, For the moment RJDemetra doesn't support user-defined calendars but it supports user-defined calendars regressors. That is to say, you have to export the corresponding regressors associated to your calendar, import them in R and then create a specification with the option usrdef.varEnabled = TRUE, usrdef.var and usrdef.varType. For example:

library(RJDemetra)
myseries <- ipi_c_eu[, "FR"]
var1 <- ts(rnorm(length(myseries))*10, start = start(myseries), frequency = 12)
var2 <- ts(rnorm(length(myseries))*100, start = start(myseries), frequency = 12)
var <- ts.union(var1, var2) # unrealistic calendar regressors
myspec1 <- x13_spec(spec = "RSA5c", tradingdays.option = "UserDefined",
                    tradingdays.test = "None",
                    usrdef.varEnabled = TRUE,
                    usrdef.var = var,
                    usrdef.varType = c("Calendar", "Calendar"))
#> Warning: With tradingdays.option = "UserDefined", the parameters tradingdays.autoadjust, tradingdays.leapyear and tradingdays.stocktd are ignored.
myreg1 <- x13(myseries, myspec1)
myreg1$regarima
#> y = regression model + arima (3, 1, 1, 0, 1, 0)
#> Log-transformation: yes
#> Coefficients:
#>          Estimate Std. Error
#> Phi(1)    -0.0458      0.047
#> Phi(2)    -0.2252      0.046
#> Phi(3)    -0.5250      0.048
#> Theta(1)  -1.0000      0.012
#> 
#>                Estimate Std. Error
#> var1         -3.546e-05      0.000
#> var2          8.332e-07      0.000
#> Easter [8]   -2.411e-02      0.005
#> LS (11-2008) -8.043e-02      0.016
#> AO (5-2011)   1.069e-01      0.019
#> LS (1-2009)  -7.975e-02      0.016
#> 
#> 
#> Residual standard error: 0.03018 on 336 degrees of freedom
#> Log likelihood = 720.3, aic =  1787 aicc =  1788, bic(corrected for length) = -6.832
ClementFeltin commented 3 years ago

I implemented things as recommended in your comment, and compared the results of the SA processing with those obtained with JDemetra. I used the same calendars (I copied the calendar in JDemetra, and imported it as a csv in RJDemetra, confer image below), and used the same specifications (RSA5c) and yet the results are different.

image

Did I do something wrong?

Also, I noticed that var <- ts.union(var1, var1) and var <- var1 do not produce the same results, is it normal?

AQLT commented 3 years ago

Hi, It is difficult to analyze the differences without having the complete reproducible example (especially to check if your specification is correctly defined). However, I can see that your calendar regressors doesn't seem to be in the correct format. Indeed, to work you have to use a ts object (see ?ts for more details). In your case, the code should look like ts(data, start = 1960, frequency = 12) with data your table with the calendar regressors. In my example, the ts.union function is use to bind the two time-series var1 and var2 (see ?ts.union for more details) so it is normal that var <- var1 gives you a different result than var <- ts.union(var1, var1): in the second case you duplicate the var1 table. To create a complete example you can export your data as "text" with the dput function (e.g.: dput(var)) and/or use the reprex package.