Skip to content

Commit

Permalink
Final points from Christiaan
Browse files Browse the repository at this point in the history
  • Loading branch information
BerendBouvy committed Nov 29, 2024
1 parent 46cf4af commit 382a0ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 55 deletions.
58 changes: 9 additions & 49 deletions book/time_series/acf.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Let us assume an arbitrary (discrete) stationary time series, $S=[S_1,S_2,...,S_
The *formal* (or: theoretical) autocovariance is defined as

$$
Cov(S_t, S_{t-\tau}) =\mathbb{E}(S_tS_{t-\tau})-\mu^2
Cov(S_t, S_{t+\tau}) =\mathbb{E}(S_tS_{t+\tau})-\mu^2
=c_{\tau}
$$

Expand All @@ -23,20 +23,20 @@ We have that $Cov(S_t, S_{t-\tau}) =Cov(S_t, S_{t+\tau})$.

Show that the covariance can be written as:

$$Cov(S_t, S_{t-\tau}) = \mathbb{E}(S_tS_{t-\tau})-\mu^2
$$Cov(S_t, S_{t+\tau}) = \mathbb{E}(S_tS_{t+\tau})-\mu^2
=c_{\tau}$$


````{admonition} Solution
:class: tip, dropdown
$$
Cov(S_t, S_{t-\tau})= \mathbb{E}[(S_t - \mathbb{E}(S_t))(S_{t-\tau} - \mathbb{E}(S_{t-\tau}))]\\
= \mathbb{E}((S_t-\mu)(S_{t-\tau}-\mu))\\
= \mathbb{E}(S_tS_{t-\tau} - \mu S_{t-\tau} - \mu S_t + \mu^2)\\
= \mathbb{E}(S_tS_{t-\tau}) - \mu \mathbb{E}(S_{t-\tau}) - \mu \mathbb{E}(S_t) + \mu^2\\
= \mathbb{E}(S_tS_{t-\tau}) - 2\mu^2 + \mu^2\\
= \mathbb{E}(S_tS_{t-\tau}) - \mu^2\\
Cov(S_t, S_{t+\tau})= \mathbb{E}[(S_t - \mathbb{E}(S_t))(S_{t+\tau} - \mathbb{E}(S_{t+\tau}))]\\
= \mathbb{E}((S_t-\mu)(S_{t+\tau}-\mu))\\
= \mathbb{E}(S_tS_{t+\tau} - \mu S_{t+\tau} - \mu S_t + \mu^2)\\
= \mathbb{E}(S_tS_{t+\tau}) - \mu \mathbb{E}(S_{t+\tau}) - \mu \mathbb{E}(S_t) + \mu^2\\
= \mathbb{E}(S_tS_{t+\tau}) - 2\mu^2 + \mu^2\\
= \mathbb{E}(S_tS_{t+\tau}) - \mu^2\\
$$
````
:::
Expand All @@ -46,7 +46,6 @@ $$
Prove that $Cov(S_t, S_{t-\tau}) =Cov(S_t, S_{t+\tau})$:



````{admonition} Solution
:class: tip, dropdown
Expand Down Expand Up @@ -77,7 +76,7 @@ $$ Cov(S_t, S_{t-\tau}) = Cov(S_t, S_{t+\tau})$$
The *formal* autocorrelation is defined as

$$
r_{\tau} = \mathbb{E}(S_tS_{t-\tau})
r_{\tau} = \mathbb{E}(S_tS_{t+\tau})
$$

```{note}
Expand Down Expand Up @@ -265,42 +264,3 @@ $$
```
:::

<!-- ## Power spectral density
The power spectral density (PSD) explains how the power (variance) of the signal is distributed over different frequencies. For instance, the PSD of a pure sine wave is flat *except* at its constituent frequency, where it will show a peak. Purely random noise has a flat power spectrum, indicating that all frequencies have an identical contribution to the variance of the signal! -->

<!-- The power spectral density (PSD) explains how the power (variance) of the signal is distributed over different frequencies. For instance, the PSD of a pure sine wave is flat *except* at its constituent frequency, where it will show a peak. Purely random noise has a flat power spectrum, indicating that all frequencies have an identical contribution to the variance of the signal!
### PSD vs ACF
Knowledge on ACF, in time domain, is mathematically equivalent to knowledge on PSD, in the frequency domain, and vice-versa. And, from here, you might have a clue of where this is taking us... The PSD is the **discrete Fourier transform (DFT)** of the ACF.
$$
\begin{align*}
\text{DFT}(\hat{c}_{\tau})&=\text{DFT}\left(\frac{1}{m}\sum_{i=1}^m s_i s_{i+\tau}\right)\\&=\frac{1}{m\Delta t}F_S(k) F_S(k)^*\\&=\frac{1}{m\Delta t}|F_S(k)|^2
\end{align*}$$
where the Fourier coefficients (see [DFT section](FFT)) are:
$$F_S(k) = \Delta t\sum_{i=1}^my_ie^{-j\frac{2\pi}{m}(k-1)(i-1)}$$
```{note}
In signal processing, it is common to write a sampled (discrete) signal as a small letter $s_i$ and the Fourier coefficients with capitals $S_k$. Since we also use capitals to indicate that $S$ is a random variable, we describe the DFT here for a realization $s_i$ of $S_i$, and use the notation $F_S(k)$ for the Fourier coefficients.
```
Conversely, the inverse discrete Fourier transform (IDFT) of the PSD is the ACF, so
$$\text{IDFT}(F_{S}(k))=\hat{c}_{\tau}, \hspace{35px} \tau = 1,...,m \hspace{5px}\text{and}\hspace{5px} k = 1,...,m$$
```{figure} ./figs/ACF_PSD.png
---
height: 300px
name: ACF_PSD
---
Time series data, autocovariance and its power spectral density plots of white noise above and colored noise (not purely random) below.
```
The PSD explains how the power (variance) of the signal is distributed over different frequencies. The PSD of a pure sine wave is flat except at its constituent frequency.
Purey random noise (i.e., white noise) has a flat power, indicating that all frequencies have identical contribution in making the variance of the signal. This is however not the case for time-correlated noise because different frequencies have different power values in making the total signal variability.
-->
7 changes: 3 additions & 4 deletions book/time_series/ar_exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"AR(1) vs AR(2) test statistic: -2 Critical value: 3.841458820694124\n",
"Fail to reject AR(1)\n",
"AR(1) vs AR(2) test statistic: 65.46386398456401 Critical value: 3.841458820694124\n",
"Reject AR(1) in favor of AR(2)\n",
"AR(2) vs AR(3) test statistic: 3.5318291727430835 Critical value: 3.841458820694124\n",
"Fail to reject AR(2)\n"
]
Expand Down Expand Up @@ -186,7 +186,6 @@
"dof = 1\n",
"crit = chi2.ppf(0.95, dof)\n",
"test_stat = n * np.log(rss1 / rss2)\n",
"test_stat = -2 \n",
"print('AR(1) vs AR(2) test statistic:', test_stat, 'Critical value:', crit)\n",
"\n",
"if test_stat > crit:\n",
Expand Down Expand Up @@ -215,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion book/time_series/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Next, we will consider stationary time series, meaning that the statistical prop
:width: 600px
:align: center
Recorded and expected global warming from 1960 to 2100 ([Huseien, Shah (2021)](https://www.mdpi.com/2071-1050/13/17/9720))
Recorded and expected global warming from 1960 to 2100, from IPCC report ([Masson-Delmotte, et al. (20219)](https://www.researchgate.net/profile/Peter-Marcotullio/publication/330090901_Sustainable_development_poverty_eradication_and_reducing_inequalities_In_Global_warming_of_15C_An_IPCC_Special_Report/links/6386062b48124c2bc68128da/Sustainable-development-poverty-eradication-and-reducing-inequalities-In-Global-warming-of-15C-An-IPCC-Special-Report.pdf))
```
2 changes: 1 addition & 1 deletion book/time_series/stationarity.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


```{admonition} Definition
A stationary time series is a stochastic process whose statistical properties do not depend on the time at which it is observed.
A stationary time series $S(t)$ is a stochastic process whose statistical properties do not depend on the time at which it is observed.
```

This means that parameters such as *mean* and *(co)variance* should remain constant over time and not follow any trend, seasonality or irregularity.
Expand Down

0 comments on commit 382a0ee

Please sign in to comment.