Skip to content

Commit ac4d051

Browse files
AR typos
1 parent e62ba91 commit ac4d051

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

16_AR.ipynb

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
"\n",
1515
"ARIMA is an abbreviation for <font color='orange'>autoregressive integrated moving average</font> and these models are what the tin says: they include autoregressive, differencing, and moving average components.\n",
1616
"\n",
17-
"In this lecture we are interested in looking at time series structure through the temporal random effects lens. We will consider a specific subclass of ARIMA family. Namely, the autoregressive models.\n",
17+
"A common way to work with time series data, is to decompose it into the trend and seasonality components, and then model thre residual random effect with ARIMA. We can view the trend and seasonality parts as the fixed effect of the model, and the residual effect as the random effect:\n",
18+
"\n",
19+
"$$\n",
20+
"\\begin{align*}\n",
21+
"y_t &= \\mu_t + \\epsilon_t, \\epsilon_t \\sim \\mathcal{N}(0, \\sigma^2),\\\\\n",
22+
"\\mu_t &= \\beta_1 t + \\beta_2 \\sin\\left(\\frac{2\\pi}{r}t\\right) + \\beta_3 \\sin\\left(\\frac{2\\pi}{r}t\\right).\n",
23+
"\\end{align*}\n",
24+
"$$\n",
25+
"\n",
26+
"Here $r$ is the seasonality period.\n",
27+
"\n",
28+
"In this lecture we are interested in looking at time series structure through the temporal random effects lens. I.e. we assume that that trend and seasonality have already been deducted $x_t := y_t - \\mu_t$. We will consider a specific subclass of ARIMA family. Namely, the autoregressive models.\n",
1829
"\n",
1930
"<font color='orange'>Autoregressive</font> models are statistical models that use a linear combination of past observations of a time series $x_{t-1}, x_{t-2},... $ to predict future values, where each observation is regressed on previous observations.\n",
2031
"\n",
@@ -31,7 +42,7 @@
3142
"\n",
3243
"The innovations $\\epsilon_t$ are independent from each other.\n",
3344
"\n",
34-
"The condition $\\mid \\phi \\mid <1$ here is required for stationarity. In order to ensure stationarity, we need to check that all roots of the characterictic polynomial $\\lambda_i$ satisfy $|\\lambda_i|<1.$ If $B$ is the backshift operator, such that $B^k = X_{t-k}$, we can rewrite the AR(1) model as \n",
45+
"The condition $\\mid \\phi \\mid <1$ here is required for stationarity. In order to ensure stationarity, we need to check that all roots of the characterictic polynomial $\\lambda_i$ satisfy $|\\lambda_i|>1.$ If $B$ is the backshift operator, such that $B^k = X_{t-k}$, we can rewrite the AR(1) model as \n",
3546
"\n",
3647
"$$\n",
3748
"x_t (1 - \\phi B) = \\epsilon_t.\n",
@@ -46,9 +57,18 @@
4657
},
4758
{
4859
"cell_type": "code",
49-
"execution_count": 2,
60+
"execution_count": 1,
5061
"metadata": {},
51-
"outputs": [],
62+
"outputs": [
63+
{
64+
"name": "stderr",
65+
"output_type": "stream",
66+
"text": [
67+
"/opt/anaconda3/envs/aims/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
68+
" from .autonotebook import tqdm as notebook_tqdm\n"
69+
]
70+
}
71+
],
5272
"source": [
5373
"import numpy as np\n",
5474
"import matplotlib.pyplot as plt\n",
@@ -318,17 +338,17 @@
318338
"Joint density of $x_1, ..., x_T$, therefore, has the form\n",
319339
"\n",
320340
"```{margin}\n",
321-
"recall the pdf of the multivariate Normal distribution which is $\\propto \\exp{(-x \\Sigma^{-1} x^T)}= \\exp{(-x Q x^T)}$ if we denote $Q = \\Sigma^{=1}$. The matrix $Q$ is called *precision matrix*.\n",
341+
"recall the pdf of the multivariate Normal distribution which is $\\propto \\exp{(-\\frac{1}{2}x^T \\Sigma^{-1} x)}= \\exp{(-\\frac{1}{2}x^T Q x)}$ if we denote $Q = \\Sigma^{-1}$. The matrix $Q$ is called *precision matrix*.\n",
322342
"```\n",
323343
"\n",
324344
"$$\n",
325345
"\\begin{align*}\n",
326346
"p(x_1, x_2, ..., x_T) &= p(x_1)p(x_2 \\mid x_1) p(x_3 \\mid x_2)... p(x_T \\mid x_{T-1})\\\\\n",
327347
"& = \\mathcal{N}_{x_1} \\left(0, \\frac{\\sigma^2}{1-\\phi^2} \\right) \\times \\mathcal{N}_{x_2} \\left(\\phi x_1,\\sigma^2 \\right) \\times ... \\times \\mathcal{N}_{x_T} \\left(\\phi x_{T-1},\\sigma^2 \\right) = \\\\\n",
328-
"& = \\frac{1}{\\sqrt{2 \\pi * \\frac{\\sigma^2}{1-\\phi^2}}} \\exp{\\left( - \\frac{x_1^2(1-\\phi^2)}{\\sigma^2} \\right)} \\times \\frac{1}{\\sqrt{2 \\pi *\\sigma^2}} \\exp{\\left( - \\frac{(x_2 - \\phi x_1)^2}{\\sigma^2} \\right)} \\times ... \\\\\n",
329-
"&\\times \\frac{1}{\\sqrt{2 \\pi *\\sigma^2}} \\exp{\\left( - \\frac{(x_T - \\phi x_{T-1})^2}{\\sigma^2} \\right)} \\\\\n",
330-
"& = \\sqrt{\\frac{1-\\phi^2}{(2 \\pi *\\sigma^2)^T}}\\exp{ \\left( -\\frac{x_1^2(1-\\phi^2) + (x_2 - \\phi x_1)^2 + ... + (x_T - \\phi x_{T-1})^2}{\\sigma^2} \\right)} \\\\\n",
331-
"& \\propto \\exp{\\left( - (x_1, x_2, ..., x_T) * Q * (x_1, x_2, ..., x_T)^T \\right)} = \\exp{ (- x Q x^T)}\n",
348+
"& = \\frac{1}{\\sqrt{2 \\pi * \\frac{\\sigma^2}{1-\\phi^2}}} \\exp{\\left( - \\frac{x_1^2(1-\\phi^2)}{2\\sigma^2} \\right)} \\times \\frac{1}{\\sqrt{2 \\pi *\\sigma^2}} \\exp{\\left( - \\frac{(x_2 - \\phi x_1)^2}{2\\sigma^2} \\right)} \\times ... \\\\\n",
349+
"&\\times \\frac{1}{\\sqrt{2 \\pi *\\sigma^2}} \\exp{\\left( - \\frac{(x_T - \\phi x_{T-1})^2}{2\\sigma^2} \\right)} \\\\\n",
350+
"& = \\sqrt{\\frac{1-\\phi^2}{(2 \\pi *\\sigma^2)^T}}\\exp{ \\left( -\\frac{x_1^2(1-\\phi^2) + (x_2 - \\phi x_1)^2 + ... + (x_T - \\phi x_{T-1})^2}{2\\sigma^2} \\right)} \\\\\n",
351+
"& \\propto \\exp{\\left( - (x_1, x_2, ..., x_T) * Q * (x_1, x_2, ..., x_T)^T \\right)} = \\exp{ (- x^T Q x)}\n",
332352
"\\end{align*}\n",
333353
"$$\n",
334354
"\n",
@@ -387,7 +407,7 @@
387407
"AR(2) process $x_t$ can be formulated mathematically as\n",
388408
"\n",
389409
"$$\n",
390-
"x_t = \\gamma_0 + \\gamma_1 \\alpha_{t-1} + \\gamma_2 \\alpha_{t-2} + \\epsilon_t, \\\\\n",
410+
"x_t = \\gamma_0 + \\gamma_1 x_{t-1} + \\gamma_2 x_{t-2} + \\epsilon_t, \\\\\n",
391411
"\\epsilon_t \\sim(0, \\sigma^2).\n",
392412
"$$\n",
393413
"\n",

0 commit comments

Comments
 (0)