I have 3 seasonal components in my data. I wanted to estimate each of them. The result is the following:

times <- seq(ISOdate(2016, 1, 1, 0, 0, 0), ISOdate(2018, 1, 1, 0, 0, 0), "hour")
y <- rnorm(length(times))

data <- data.frame(date = times, month = factor(months(times)), 
               day = factor(weekdays(times)), 
               hour = factor(format(times, "%H")), 
               y = y)

lm(y ~ month + day + hour, data = data) # estimating coefficients of seasonal effects

Now I want to take the results and deseasonalize the data. How can I use my results and apply it to the data and deseasonalize the data with it? Another question is, what is the best reference to take for the linear model. In this case I took Monday, Friday and hour00. But the results would be different if I take different references to build the linear model on. So what is the best reference to take?

  • $\begingroup$ @StephanKolassa Just one more thing. I really don't understand why you edited the references of my original post. You edited it to Monday and Friday. This is wrong, as these are both weekdays and the reference for the month is missing. $\endgroup$ Mar 25, 2018 at 21:20

1 Answer 1


I don't think there is a good way to deseasonalize based on a linear model.

You may want to look at Forecasting: Principles and Practice by Hyndman & Atahanasopoulos, specifically the chapter on decomposition, and think about applying a moving average to extract the trend-cycle components, but you would need a rather wide kernel to account for your triple seasonality. Or apply single exponential smoothing with a small smoothing parameter to the same effect. However, you still only have two outer (yearly) cycles - that's not a lot to estimate and remove the seasonality.

An alternative would be to apply an algorithm to your data that is specifically built to deal with the involved, e.g., or , both available in the forecast package. Unfortunately, tbats() does not converge for me, and bats() runs for a long time, but you may want to look for some inspiration into the original paper by De Livera, Hyndman & Snyder (JASA, 2011).

  • $\begingroup$ I wanted to reproduce my data. In fact, the different time points correlate quite strongly with each other. The thing is, if I take the residuals the data fluctuates around 0. Is it possible to take the residuals and add the mean of y so that the data fluctuates around the mean again? I have already tried the tbats() command, but it gives me trend outputs which are actually seasonal variations. (Applied to my data). $\endgroup$ Mar 22, 2018 at 9:40
  • $\begingroup$ And there is still the question: Taking the residuals give different deseasonalized effects depending on the reference I take. So what is the best reference to take then? $\endgroup$ Mar 22, 2018 at 10:16
  • $\begingroup$ Sorry, I didn't think this through. My bad. My answer really is no answer, so I'll edit it heavily. $\endgroup$ Mar 24, 2018 at 7:12
  • $\begingroup$ Ok. I appreciate your help. I also should have made clear, that I want to deseasonalize the data in order to build a ARMA-GARCH model with the deseasonalized data. I will stick to the linear case (the residuals with the addition of the mean of y[ I add the mean of y for visualisation purposes]), take the first diff to remove the trend and build the ARCH-GARCH model. Even if it is not perfect, I guess it will be alright for my work. $\endgroup$ Mar 25, 2018 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.