Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_tradingdays #76

Open
lauramartinez09 opened this issue Dec 10, 2024 · 7 comments
Open

set_tradingdays #76

lauramartinez09 opened this issue Dec 10, 2024 · 7 comments

Comments

@lauramartinez09
Copy link

I am working with a time series where the effect of leap years is significant, while the effects of working days and Easter do not show significance. My goal is to adjust the series considering only the effect of leap years, but I am unable to do so using the set_tradingdays function to account for only this effect. I am attaching the code to better illustrate my question.

spec <- rjd3tramoseats::tramoseats_spec("rsa3")
newspec <- rjd3toolkit::set_tradingdays(spec, option = "WorkingDays", leapyear = "LeapYear" )
new_spec<- rjd3toolkit::set_easter(newspec, type = "IncludeEaster")
res_WD_parados <- rjd3tramoseats::tramoseats_fast(parados_ts, spec = new_spec)
summary(res_WD_parados)
Model: TRAMO-SEATS
Log-transformation: no
SARIMA model: (1,1,0) (1,0,1)

Coefficients
Estimate Std. Error T-stat Pr(>|t|)
phi(1) -0.52568 0.09371 -5.609 2.81e-07 ***
bphi(1) -0.66654 0.11538 -5.777 1.40e-07 ***
btheta(1) 0.31598 0.17155 1.842 0.0692 .

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Regression model:
Estimate Std. Error T-stat Pr(>|t|)
td 1.923 3.103 0.620 0.5372
lp -31.916 15.636 -2.041 0.0446 *
easter -5.428 8.655 -0.627 0.5324
LS (2008-10-01) 284.009 62.544 4.541 1.98e-05 ***
TC (2009-01-01) 382.615 56.781 6.738 2.35e-09 ***
LS (2020-07-01) 360.652 59.882 6.023 5.13e-08 ***
TC (2021-10-01) -305.984 52.912 -5.783 1.41e-07 ***

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1
Number of observations: 91, Number of effective observations: 90, Number of parameters: 11
Loglikelihood: -533.6932
Standard error of the regression (ML estimate): 88.62875
AIC: 1089.386, AICc: 1092.771, BIC: 1116.884

@annasmyk
Copy link
Member

annasmyk commented Dec 10, 2024

Indeed: if in set_tradingdays option="None", leapyear effect won't be computed even if specified
Two solutions here

  • set option = "WorkingDays" and coefficient to zero
  • use a userdefined leap year regressor with userdefined option

@AQLT
Copy link
Contributor

AQLT commented Dec 10, 2024

To create the leap year regressor I would rather recommend using the rjd3tookit::lp_variable() function to be sure to use the same code as in JDemetra+.

@TanguyBarthelemy
Copy link
Contributor

TanguyBarthelemy commented Dec 10, 2024

Of course... My message was confusing (so I deleted it)
@AQLT is right!

@lauramartinez09
Copy link
Author

lauramartinez09 commented Dec 11, 2024

What I explained yesterday, I did it this way. Could you confirm if I did it correctly?

SpainCalendar <- national_calendar(list(
  special_day("NEWYEAR"),
  fixed_day( month = 1, day = 6),
  special_day( "MAYDAY"), # dia del trabajador
  special_day( "ASSUMPTION"),  # 15 de agosto
  fixed_day(month = 10, day = 12),
  special_day("ALLSAINTSDAY"), # dia de todo los santos
  fixed_day(month = 12, day = 6),
  fixed_day(month = 12, day = 8),
  special_day( "CHRISTMAS")
))
## Regresores de calendario (cuatrimestre):
## - Working Days (1 regresor) ##
groups <- c(1, 1, 1, 1, 1, 0, 0)
frequency <- 4
start <- c(2002,1)
end = c(2025, 4)
length = (end[1] - start[1]) * 4 + end[2] - start[2] 
# longitud = (año_final - año_inicio) * frecuencia + (trimestre_final - trimestre_inicio)
ly<-lp_variable(frequency = frequency, start = start,length = length)
reg <- calendar_td(SpainCalendar, frequency = frequency, start = start,
                   length = length, groups = groups, contrasts = T)
regresseurs_JO <- ts(reg, start = start, frequency = frequency)
regresseurs_JO <- ts.union(regresseurs_JO,ly)
colnames(regresseurs_JO) <- c("week_Days","leap_year")
y <- regresseurs_JO[, "leap_year"]
vars <- list(reg1=list(x=y))
my_context <- modelling_context(variables = vars)
newspec <- set_easter(spec, type = "includeEaster")
new_spec <- rjd3toolkit::set_tradingdays(spec, option = "UserDefined", uservariable = "reg1.x")
res_WD_parados <- rjd3tramoseats::tramoseats_fast(parados_ts, spec = new_spec, context = my_context)
summary(res_WD_parados)
Model: TRAMO-SEATS
Log-transformation: no 
SARIMA model: (1,1,0) (1,0,1)

Coefficients
          Estimate Std. Error T-stat Pr(>|t|)    
phi(1)    -0.51957    0.09299 -5.587 2.93e-07 ***
bphi(1)   -0.66488    0.11465 -5.799 1.20e-07 ***
btheta(1)  0.31326    0.17088  1.833   0.0704 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Regression model:
                Estimate Std. Error T-stat Pr(>|t|)    
usertd            -32.33      15.31 -2.112   0.0378 *  
LS (2008-10-01)   284.19      61.54  4.618 1.44e-05 ***
TC (2009-01-01)   391.39      55.35  7.071 4.91e-10 ***
LS (2020-07-01)   360.27      59.69  6.035 4.55e-08 ***
TC (2021-10-01)  -299.12      51.62 -5.794 1.26e-07 ***

@annasmyk
Copy link
Member

We don't have your data nor the "spec" you start with so hard to confirm with certitude
your code looks ok though (you don't need to create a calendar and all the the related regressors just to use the leap year)
you don't see the results for your Easter regressor because it is tested and rejected (use the test="None" option otherwise)
It is very tricky to estimate a leap year effect on quarterly data, but this one seems significant...

@lauramartinez09
Copy link
Author

My defined specification is as follows: spec <- rjd3tramoseats::tramoseats_spec("rsa3"). In the code, I do not include the Easter effect or the trading days effect because, as I observed in the first code I provided, both effects are not significant. What I want to do is add the leap year effect as a regressor variable. My question is whether it has been correctly implemented, which can be verified in the second code I provided.

@annasmyk
Copy link
Member

It is correctly implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants