GitHub

@@ -34,8 +34,6 @@ import jax.numpy as jnp

3434

from jax import random

3535

import matplotlib.pyplot as plt

363637-

%matplotlib inline

38-3937

import logging

4038

logging.basicConfig()

4139

logger = logging.getLogger('pymc')

@@ -71,7 +69,7 @@ $$ (eq:themodel_2)

71697270737174-

Consider a sample $\{y_t\}_{t=0}^T$ governed by this statistical model.

72+

Consider a sample $\{y_t\}_{t=0}^T$ governed by this statistical model.

75737674

The model

7775

implies that the likelihood function of $\{y_t\}_{t=0}^T$ can be **factored**:

@@ -80,7 +78,7 @@ $$

8078

f(y_T, y_{T-1}, \ldots, y_0) = f(y_T| y_{T-1}) f(y_{T-1}| y_{T-2}) \cdots f(y_1 | y_0 ) f(y_0)

8179

$$

828083-

where we use $f$ to denote a generic probability density.

81+

where we use $f$ to denote a generic probability density.

84828583

The statistical model {eq}`eq:themodel`-{eq}`eq:themodel_2` implies

8684

@@ -95,7 +93,7 @@ We want to study how inferences about the unknown parameters $(\rho, \sigma_x)$

95939694

Below, we study two widely used alternative assumptions:

979598-

- $(\mu_0,\sigma_0) = (y_0, 0)$ which means that $y_0$ is drawn from the distribution ${\mathcal N}(y_0, 0)$; in effect, we are **conditioning on an observed initial value**.

96+

- $(\mu_0,\sigma_0) = (y_0, 0)$ which means that $y_0$ is drawn from the distribution ${\mathcal N}(y_0, 0)$; in effect, we are **conditioning on an observed initial value**.

999710098

- $\mu_0,\sigma_0$ are functions of $\rho, \sigma_x$ because $y_0$ is drawn from the stationary distribution implied by $\rho, \sigma_x$.

10199

@@ -105,20 +103,20 @@ Below, we study two widely used alternative assumptions:

105103106104

Unknown parameters are $\rho, \sigma_x$.

107105108-

We have independent **prior probability distributions** for $\rho, \sigma_x$ and want to compute a posterior probability distribution after observing a sample $\{y_{t}\}_{t=0}^T$.

106+

We have independent **prior probability distributions** for $\rho, \sigma_x$ and want to compute a posterior probability distribution after observing a sample $\{y_{t}\}_{t=0}^T$.

109107110108

The notebook uses `pymc4` and `numpyro` to compute a posterior distribution of $\rho, \sigma_x$. We will use NUTS samplers to generate samples from the posterior in a chain. Both of these libraries support NUTS samplers.

111109112110

NUTS is a form of Monte Carlo Markov Chain (MCMC) algorithm that bypasses random walk behaviour and allows for convergence to a target distribution more quickly. This not only has the advantage of speed, but allows for complex models to be fitted without having to employ specialised knowledge regarding the theory underlying those fitting methods.

113111114112

Thus, we explore consequences of making these alternative assumptions about the distribution of $y_0$:

115113116-

- A first procedure is to condition on whatever value of $y_0$ is observed. This amounts to assuming that the probability distribution of the random variable $y_0$ is a Dirac delta function that puts probability one on the observed value of $y_0$.

114+

- A first procedure is to condition on whatever value of $y_0$ is observed. This amounts to assuming that the probability distribution of the random variable $y_0$ is a Dirac delta function that puts probability one on the observed value of $y_0$.

117115118116

- A second procedure assumes that $y_0$ is drawn from the stationary distribution of a process described by {eq}`eq:themodel`

119117

so that $y_0 \sim {\cal N} \left(0, {\sigma_x^2\over (1-\rho)^2} \right) $

120118121-

When the initial value $y_0$ is far out in a tail of the stationary distribution, conditioning on an initial value gives a posterior that is **more accurate** in a sense that we'll explain.

119+

When the initial value $y_0$ is far out in a tail of the stationary distribution, conditioning on an initial value gives a posterior that is **more accurate** in a sense that we'll explain.

122120123121

Basically, when $y_0$ happens to be in a tail of the stationary distribution and we **don't condition on $y_0$**, the likelihood function for $\{y_t\}_{t=0}^T$ adjusts the posterior distribution of the parameter pair $\rho, \sigma_x $ to make the observed value of $y_0$ more likely than it really is under the stationary distribution, thereby adversely twisting the posterior in short samples.

124122

@@ -129,7 +127,7 @@ We begin by solving a **direct problem** that simulates an AR(1) process.

129127130128

How we select the initial value $y_0$ matters.

131129132-

* If we think $y_0$ is drawn from the stationary distribution ${\mathcal N}(0, \frac{\sigma_x^{2}}{1-\rho^2})$, then it is a good idea to use this distribution as $f(y_0)$. Why? Because $y_0$ contains information about $\rho, \sigma_x$.

130+

* If we think $y_0$ is drawn from the stationary distribution ${\mathcal N}(0, \frac{\sigma_x^{2}}{1-\rho^2})$, then it is a good idea to use this distribution as $f(y_0)$. Why? Because $y_0$ contains information about $\rho, \sigma_x$.

133131134132

* If we suspect that $y_0$ is far in the tails of the stationary distribution -- so that variation in early observations in the sample have a significant **transient component** -- it is better to condition on $y_0$ by setting $f(y_0) = 1$.

135133

@@ -273,7 +271,7 @@ summary_y0

273271274272

Please note how the posterior for $\rho$ has shifted to the right relative to when we conditioned on $y_0$ instead of assuming that $y_0$ is drawn from the stationary distribution.

275273276-

Think about why this happens.

274+

Think about why this happens.

277275278276

```{hint}

279277

It is connected to how Bayes Law (conditional probability) solves an **inverse problem** by putting high probability on parameter values

Read the original on github.com ↗