# Differencing a perfectly seasonal time series [closed]

I was just playing around today with differencing and wanted to see what happened if I differenced a sine function. As far as I am aware, differencing usually results in producing small auto correlations.

My expectation was that differencing a perfectly seasonal function would result in near 0 ACFs. What happened was that my ACFs were just as large as the sine function ACFs.

To set this up I used the following code:

library(tidyverse)

#prepare data
df <- as_tibble(list(x = seq(0, 8*2*pi, length.out = 5000))) %>%
mutate(y = sin(x),
diff = c(NA, diff(y)),
date = seq(as_date("2010-01-01"), by = "1 day", length.out = 5000))

df %>% ggplot(aes(y = y, x = date))+
geom_line() +
geom_line(aes(y = diff))


Code for the ACFs:

library(tsibblestats)
df %>%
na.omit() %>%
ACF(value = diff)

lag   acf
<lag> <dbl>
1  1DAY 1.000
2  2DAY 0.999
3  3DAY 0.998
4  4DAY 0.998
5  5DAY 0.997
6  6DAY 0.996
7  7DAY 0.995
8  8DAY 0.994
9  9DAY 0.992
10 10DAY 0.991


and sine acf

df %>%
na.omit() %>%
ACF(value = y)
lag   acf
<lag> <dbl>
1  1DAY 1.000
2  2DAY 1.000
3  3DAY 1.000
4  4DAY 0.999
5  5DAY 0.999
6  6DAY 0.998
7  7DAY 0.998
8  8DAY 0.997
9  9DAY 0.996
10 10DAY 0.995


If differencing is supposed to make a seasonal time series stationary, why is this not the case in a perfectly seasonal time series, as shown with the sine function?

## closed as unclear what you're asking by Stephan Kolassa, Michael Chernick, kjetil b halvorsen, Carl, mdeweyJul 3 '18 at 17:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• @StephanKolassa Thanks for pointing out the error in my code, and pronving the insignificant ACFs. – Alex Jul 1 '18 at 23:35
• @StephanKolassa I agree that the code is not particularly straightforward, but the question is clearly about y=sin(x) and diff(y), neither of which is stationary, and not about x (that seq expression) or diff(x). – Chris Haug Jul 4 '18 at 12:00
• @ChrisHaug: thanks! I completely forgot including a sin()... – Stephan Kolassa Jul 4 '18 at 12:26

In the case of a deterministic sine process, if the period of the sine is an integer number of steps (say, $k$), then the difference at that lag ($z_t = y_t - y_{t-k}$) will give you a stationary process. This is obvious from the fact that the periodicity will make that difference zero at all times.
x = seq(0, 8*2*pi, length.out = 5000 + 1)

will mean that the period is exactly 5000/8 = 625, and therefore the difference $y_t - y_{t-625} = 0$ is stationary. If you try it in software you will probably not get exactly zero at all times and you may get some residual autocorrelation; this is due to finite precision arithmetic.