# Autocorrelation of a random sequence with a periodic signal

Suppose that $$\{Y_t\}_{t\in\mathbb Z}$$ is a sequence of random variables given by $$Y_t =s_t+\varepsilon_t$$ for $$t\in\mathbb Z$$, where

• $$\{s_t\}_{t\in\mathbb Z}$$ is a deterministic periodic sequence such that $$s_{t+p}=s_t$$ with some $$p\ge2$$ and $$\sum_{t=1}^ps_t=0$$;
• $$\{\varepsilon_t\}_{t\in\mathbb Z}$$ is white noise with mean $$0$$ and variance $$\sigma^2$$.

The autocovariance function of $$\{Y_t\}_{t\in\mathbb Z}$$ is given by \begin{align*} \operatorname{Cov}(Y_t,Y_{t+h}) &=\operatorname E[(Y_t-\operatorname EY_t)(Y_{t+h}-\operatorname EY_{t+h})]\\ &=\operatorname E[(s_t+\varepsilon_t-s_t)(s_{t+h}+\varepsilon_{t+h}-s_{t+h})]\\ &=\operatorname E[\varepsilon_t\varepsilon_{t+h}]\\ &= \begin{cases} \sigma^2&\text{if}\ h=0;\\ 0&\text{if } h\ne0. \end{cases} \end{align*} This means that $$\{Y_t\}_{t\in\mathbb Z}$$ is a sequence of uncorrelated random variables. However, if I run some simple simulation in R, the estimated autocorrelation function does not seem to be close to $$0$$ at all lags except $$0$$.

What am I missing here? Am I making a mistake somewhere?

Any help is much appreciated!

This is the R code as well as a plot of the estimated autocorrelation function.

set.seed(1)
d <- 7
n <- 100 * d
y <- rep(rnorm(d), n/d) + rnorm(n)
acf(y, type = "correlation")


• Basically, you have $p$ different random variables since they will differ in mean by $s_t$. Then you calculate the ACF of these $p$ different random variables combined, which treats them as coming from a single population whose mean is estimated by the sample mean. It is this bad estimate of the mean-- there should be $p$ functions estimated to estimate the mean-- that causes the "problem" of a poorly behaved ACF. Commented Dec 7, 2021 at 13:06

From your model, $$s_t$$ is treated as an (unknown) constant; hence, it affects the mean of $$y_t$$, which affects the calculation of the sample ACF as you have shown in the graph. Normally when you calculate the ACF/PACF/EACF, you calculate it for the residuals since all of the residuals will come from the same family. Clearly, $${\tt acf(y - rep(rnorm(d), n/d), type = "corr")}$$ will give a well-behaved ACF.

However if we must estimate $$s_t$$ for $$t=1,\cdots,p$$, then it is clear that this can be written as a linear model with $$\begin{eqnarray*} y_t = \sum_{i=0}^{p-1} \beta_i \mbox{I}\left[t\bmod p = i\right] + \varepsilon_t, \end{eqnarray*}$$ where $$\beta_0$$ represents $$s_p$$.

Instead of working with $$\boldsymbol{y} = \left(y_1, \cdots, y_n\right)^{\prime}$$, let us define $$\boldsymbol{y}_i = \left(y_{i1}, \cdots, y_{ip}\right)^{\prime}$$ and $$\boldsymbol{y} = \left(\boldsymbol{y}_1^{\prime}, \cdots, \boldsymbol{y}_{n/p}^{\prime}\right)^{\prime}$$. Clearly the design matrix $$\boldsymbol{X} = \boldsymbol{j}_{n/p} \otimes \boldsymbol{I}_p$$; hence, $$\left(\boldsymbol{X}^{\prime} \boldsymbol{X} \right)^{-1} = \frac{p}{n}\boldsymbol{I}_p$$, and the MLE of $$\boldsymbol{\beta} = \left(\beta_0, \cdots, \beta_{p-1}\right)^{\prime}$$ is $$\begin{eqnarray*} \widehat{\boldsymbol{\beta}} = \left(\boldsymbol{X}^{\prime} \boldsymbol{X} \right)^{-1} \boldsymbol{X}^{\prime} \boldsymbol{y} = \frac{p}{n}\sum_{i=1}^{n/p}\boldsymbol{y}_i \end{eqnarray*}$$

Returning to your code, we have

set.seed(1)
d <- 7
n <- 100 * d
z <- rep(rnorm(d), n/d)
y <- z + rnorm(n)
acf(y, type = "correlation")
X = kronecker(rep(1,n/d),diag(1,d))
res = (diag(1,n) - X%*%solve(t(X)%*%X)%*%t(X))%*%y
acf(res, type = "correlation")


It is interesting to note that this set-up is identical the cell-means model formulation of a one-way ANOVA

• Thank you for your answer. However, I still do not see why there is a discrepancy between the ACF and the estimated ACF of the R example. I would expect that the ACF would show that $Y_t$’s are correlated as the estimated ACF indicates. I understand that $\{s_t\}_{t\in\mathbb Z}$ can be estimated and we can obtain the residuals of the model but this is not what my question is about. Commented Dec 7, 2021 at 13:05
• Why would you expect that the estimated ACF would show that $Y_t$'s are correlated when you have proven theoretically that they are uncorrelated. The reason you want to obtain the residuals is to plot the estimated ACF (of the residuals) to check that your original modelling assumption is correct, i.e. uncorrelated errors. Commented Dec 7, 2021 at 13:11
• I was confused with this discrepancy but it is clear now where the problem was. I used the actual expected value when I calculated the covariance function but this expected value depends on $t$ and is not estimated correctly by the acf() function. Commented Dec 7, 2021 at 13:16