Last updated: 2022-03-18

Checks: 7 0

Knit directory: ~/Documents/Winter_Quarter_2022/Fundamentals/jaurbanChicago.github.io/bin/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(12345) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 742e5e6. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Untracked files:
    Untracked:  .DS_Store
    Untracked:  .Rhistory

Unstaged changes:
    Deleted:    New Folder With Items/.DS_Store
    Deleted:    New Folder With Items/Genetic_Drift_Markov_Chain.Rmd
    Deleted:    New Folder With Items/_site.yml
    Deleted:    New Folder With Items/include/footer.html
    Deleted:    index.html

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (bin/diffusion_process.Rmd) and HTML (docs/diffusion_process.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 742e5e6 jaurbanChicago 2022-03-18 Added diffusion_approx
html 742e5e6 jaurbanChicago 2022-03-18 Added diffusion_approx
html 0ca3500 jaurbanChicago 2022-03-17 Added diff html
Rmd 6ececba jaurbanChicago 2022-03-17 update diff rmd
html a311740 jaurbanChicago 2022-03-17 Removed all htmls
Rmd 6515916 jaurbanChicago 2022-03-17 Added diff process rmd
Rmd 43750b8 jaurbanChicago 2022-03-17 deleted diffusion_process.Rmd
html 32d40e6 jaurbanChicago 2022-03-17 Added html
Rmd 06472ac jaurbanChicago 2022-03-17 Added diffusion_process rmd and html
html 06472ac jaurbanChicago 2022-03-17 Added diffusion_process rmd and html

In this vignette, we will learn about an important type of random process called the diffusion process.

Prerequisites

  • A good understanding of calculus (in particular, Taylor’s theorem)
  • Previous exposure to discrete-time and continuous-time Markov chain

Introduction

Stochastic processes are classified based on time parameter and state space, both of which can be either discrete or continuous. This leads to four categories of stochastic processes. We spent most of the time in lectures to study processes with discrete state space and refer to them as “chains”. Now let’s consider the case in which both time parameter and state space are continuous.

Let \(\{X_t, t \geq 0\}\) be a stochastic process, where \(X_t\) is a continuous random variable with state space \(S = \mathbb{R}\). \(X_t\) is the value of the process at time \(t\), and we can interpret it as the location of a random particle moving in 1-d (i.e.: on a line). Although we can certainly consider more interesting scenarios where the particle lives in a space of higher dimensions and describe its position with a random vector, for simplicity we only deal with the 1-d case here.

Just like we focused on Markov chain in lectures, in this vignette we focus on a special class of stochastic process called the Markov process. Markov process is essentially the same concept as Markov chain, except that Markov chain implicitly assumes a stochastic process with discrete state space. 

Definition. The stochastic process \(\{X_t, t \geq 0\}\) described above is a Markov process if it satisfies the Markov property-i.e., for any sequence of times \(0 < t_1 < \dots < t_{n-1} < t_n\) and \(x_0, x_1, \dots, x_{n-1}, y \in S\), we have: \[ \begin{aligned} \mathbb{P}(X_{t_n} \leq y \mid X_0 = x_0, X_{t_1} &= x_1, \dots, X_{t_{n-1}}= x_{n-1}) = \mathbb{P}(X_{t_n} \leq y \mid X_{t_{n-1}} = x_{n-1}) \end{aligned} \] In plain words, a random process possesses Markov property if where it goes depends on where it is but not where it was. Note that the probability in the definition is stated in terms of cumulative distribution due to the continuous nature of the state space. On the other hand, we can have equalities in what we condition on because once these continuous random variables are realized, they become fixed, discrete values.

We also need to characterize the randomness when transitioning between different states. Recall that each discrete-time Markov chain (DTMC) has a transition probability matrix, and each continuous-time Markov chain (CTMC) has an infinitesimal generator that is linked to a transition probability function. For Markov process with continuous time and continuous state space, we define the transition kernel as follows.

Definition. The transition kernel of a Markov process \(\{X_t, t \geq 0\}\) that is continuous in time and state is the cumulative distribution function for a transition from state \(x\) at time \(s\) to state \(y\) at time \(t\), \(s < t\). The transition kernel is denoted as: \[ P(x, s, y, t) := \mathbb{P}(X_t \leq y \mid X_s = x) \] The corresponding transition density of this transition kernel is: \[ p(x, s, y, t) := \frac{d}{dy}P(x, s, y, t) \] Of course, by the law of total probability, our transition density satisfies the Chapman-Kolmogorov equation: \[ p(x, s, y, t) = \int_{\mathbb{R}} p(x,s,z,u)p(z,u,y,t)dz \hspace{20mm} (s<u<t) \] Note that this is a complete analog of the CTMC case. Specifically, let \(\{X(t): t \geq 0\}\) be a CTMC with state space \(\Omega\) and transition probability functions \((P_{ij}(t))_{i,j \in \Omega}\). Then for any \(s, t \geq 0\): \[ P_{ij}(s+t) = \sum_{k \in \Omega} P_{ik}(s)P_{kj}(t) \] Therefore, we essentially replace summation with integral (again, due to the continuous nature of the state space).

As before, we are mostly interested in the case where the process is time homogeneous.

Definition. The transition density is said to be time-homogeneous if for all \(\Delta t > 0\): \[ p(x, s, y, t) = p(x, s+\Delta t; t + \Delta t) \] In this case, because the density only depends on the length of time interval between transitions, we can define \(t' := t - s\) and adopt a simpler notation: \[ p(x, y, t') := p(x, s, y, t) \]

Diffusion process in 1-d

Now we are ready to define diffusion process. A diffusion process can be uniquely specified by its two (deterministic) components: infinitesimal mean (sometimes called drift) and infinitesimal variance (sometimes called quadratic variation).

Definition. Let \(\{X_t, t \geq 0\}\) be a Markov process with state space \(S \in \mathbb{R}\), having a transition density given by \(p(x,s,y,t)\). Then \(\{X_t, t \geq 0\}\) is a diffusion process if: \[ \begin{aligned} \mu(x, s) &= \lim_{\Delta t \rightarrow 0} \frac{1}{\Delta t} \int_{\mathbb{R}} (y - x) p(x,s,y,s+\Delta t)dy\\ \sigma^2(x, s) &= \lim_{\Delta t \rightarrow 0} \frac{1}{\Delta t} \int_{\mathbb{R}} (y - x)^2 p(x,s,y,s+\Delta t)dy\\ 0 &= \lim_{\Delta t \rightarrow 0} \frac{1}{\Delta t} \int_{\mathbb{R}} |y - x|^q p(x,s,y,s+\Delta t)dy, \hspace{1mm} \text{for all } q > 2 \end{aligned} \] Here, \(\mu(x, s)\) is the infinitesimal mean and \(\sigma^2(x, s)\) is the infinitesimal variance. The third equation is a technical condition that ensures the sample paths, realizations of the process, are continuous.

Forward and backward equations

As usual, we can use the Chapman-Kolmogorov equation to derive Kolmogorov forward and backward equations for a diffusion process. For simplicity, we restrict ourselves to the time-homogeneous case.

By time-homogeneity, we can rewrite the transition density as \(p(x, x',t)\), where \(x\) is the initial state and \(x'\) is the endpoint after \(t\) units of time. Consider the time derivative of the transition density: \[ \frac{d}{dt}p(x,x',t) = \lim_{\Delta t \rightarrow 0} \frac{p(x,x',t+\Delta t) - p(x,x',t)}{\Delta t} \] Note that we can expand \(p(x,x',t+\Delta t)\) with the Chapman-Kolmogorov equation in two ways: \[ \begin{aligned} p(x, x', t+\Delta t) &= \int_{\mathbb{R}} p(x,z,t)p(z,x',\Delta t)dz\\ p(x,x',t+\Delta t) &= \int_{\mathbb{R}} p(x,z,\Delta t)p(z,x',t)dz \end{aligned} \] The first one corresponds to the forward equation and the second one corresponds to the backward equation. We derive the backward equation first. By Taylor expansion of \(p(z,x',t)\) in \(z\) about \(x\), we get: \[ \begin{aligned} p(z,x',t) &= p(x,x',t) + (z-x)\frac{d}{dx}p(x,x',t)+\frac{1}{2}(z-x)^2\frac{d^2}{dx^2}p(x,x',t) + O(\Delta t^3) \end{aligned} \] Substituting back, we have: \[ \begin{aligned} p(x,x',t+\Delta t) - p(x, x', t) &= p(x,x',t) \int_{\mathbb{R}} p(x,z,\Delta t)dz \\ &+ \frac{d}{dx}p(x,x',t)\int_{\mathbb{R}}(z-x)p(x,z,\Delta t)dz \\ &+\frac{1}{2}\frac{d^2}{dx^2}p(x,x',t) \int_{\mathbb{R}} (z-x)^2 p(x,z,\Delta t)dz \\ &+ O(\Delta t^3) \\ &- p(x,x',t) \end{aligned} \] Plugging in the definition of diffusion process and divide both sides of the equation by \(\Delta t\). Take the limit as \(\Delta t \rightarrow 0\), we obtain the backward equation: \[ \frac{d}{dt}p(x,x',t) = \mu(x) \frac{d}{dx}p(x,x',t) + \frac{1}{2} \sigma^2(x) \frac{d^2}{dx^2}p(x,x',t) \] It is a backward equation because it captures the dynamics of all the states going backward in time.

To derive the forward equation, we first change the notation of transition density to \(p(x_0, x, t)\). Here, the initial state is \(x_0\), and \(x\) is the endpoint after \(t\) units of time. Again, we have the following time derivative: \[ \begin{aligned} \frac{d}{dt}p(x_0,x,t) &= \lim_{\Delta t \rightarrow 0} \frac{p(x_0,x,t+\Delta t) - p(x_0,x,t)}{\Delta t} \\ &= \lim_{\Delta t \rightarrow 0} \frac{\int_{\mathbb{R}}p(x_0,z,t)p(z,x,\Delta t)dz - p(x_0,x,t)}{\Delta t} \end{aligned} \] Instead of performing Taylor expansion, we adopt a different strategy. The intuition behind this strategy is that if we want to show two functions (say \(f(x)\) and \(g(x)\)) are identical, we can instead demonstrate that \(\int_{\mathbb{R}}f(x)h(x)dx =\int_{\mathbb{R}}g(x)h(x)dx\) for all \(h(x)\) with some good properties (e.g.: smooth, compactly supported). This set of \(h(x)\) is called the set of test functions. If you find it confusing, it’s okay to take it for granted as this is a very standard trick in mathematical analysis. If you want to see more details, check out this Wikipedia page on distribution: https://en.wikipedia.org/wiki/Distribution_(mathematics).

We pick some smooth, compactly supported test function \(h\) and evaluate the following integral: \[ \begin{aligned} \int_{\mathbb{R}}h(x)dx\int_{\mathbb{R}}p(x_0,z,t)p(z,x,\Delta t)dz &= \int_{\mathbb{R}}h(x)\{\int_{\mathbb{R}}p(x_0,z,t)p(z,x,\Delta t)dz\}dx \hspace{10mm} (*) \\ &= \int_{\mathbb{R}}p(x_0,z,t)\int_{\mathbb{R}}h(x)p(z,x,\Delta t)dxdz \end{aligned} \] Now we can do Taylor expansion for \(h(x)\) about \(z\). Leveraging the definition of diffusion process and dropping the higher-order terms, we have for small \(\Delta t\): \[ \begin{aligned} \int_{\mathbb{R}}p(x_0,z,t)\int_{\mathbb{R}}h(x)p(z,x,\Delta t)dxdz &= \int_{\mathbb{R}}p(x_0,z,t)\int_{\mathbb{R}} [h(z) + (x-z) \frac{d}{dz}h(z)+\frac{1}{2} (x-z)^2 \frac{d^2}{dz^2}h(z) + O(\Delta t^3)] p(z,x,\Delta t)dxdz \\ &= \int_{\mathbb{R}}p(x_0,z,t) [h(z) + \mu(z) \frac{d}{dz}h(z)\Delta t + \frac{1}{2} \sigma^2(z) \frac{d^2}{dz^2}h(z) \Delta t] dz \\ &= \int_{\mathbb{R}} p(x_0,z,t) h (z) dz + \Delta t \int_{\mathbb{R}} p(x_0,z,t) \mu(z) h'(z) dz + \Delta t \int_{\mathbb{R}} p(x_0,z,t) \frac{1}{2} \sigma^2(z) h''(z) dz \\ &= \int_{\mathbb{R}} p(x_0,z,t) h (z) dz - \Delta t \int_{\mathbb{R}} h(z) \frac{d}{dz}\{p(x_0,z,t) \mu(z)\} dz + \Delta t \int_{\mathbb{R}} \frac{1}{2} h(z) \frac{d^2}{dz^2}\{p(x_0,z,t)\sigma^2(z)\}dz \\ &= \int_{\mathbb{R}} h(x) [p(x_0,x,t) - \Delta t\frac{d}{dx}\{p(x_0,x,t) \mu(x)\} + \frac{1}{2} \Delta t \frac{d^2}{dx^2}\{p(x_0,x,t)\sigma^2(x)\}] dx \hspace{10mm} (**) \end{aligned} \] The calculations might seem a bit daunting at first glance. However, note that because \(h\) and \(h'\) both have compact support, they vanish at \(-\infty\) and \(\infty\). Using this fact, we can compute the integrals easily. Specifically, the fourth equality follows from integration by part, and \(\int_{\mathbb{R}} h'(x) f(x) dx\) is just \(-\int_{\mathbb{R}} h(x) f'(x) dx\) in this case.

Now, comparing \((*)\) with \((**)\) gives: \[ \int_{\mathbb{R}}p(x_0,z,t)p(z,x,\Delta t)dz = p(x_0,x,t) - \Delta t\frac{d}{dx}\{p(x_0,x,t) \mu(x)\} + \frac{1}{2} \Delta t \frac{d^2}{dx^2}\{p(x_0,x,t)\sigma^2(x)\} \] Reorder the terms and take the limit as \(\Delta t \rightarrow 0\), we obtain the forward equation: \[ \frac{d}{dt}p(x_0,x,t) = -\frac{d}{dx}\{p(x_0,x,t) \mu(x)\} + \frac{1}{2}\frac{d^2}{dx^2}\{p(x_0,x,t)\sigma^2(x)\} \] The Kolmogorov forward equation is also referred to as the Fokker-Plank equation. It is a forward equation because it captures the dynamics of all the states going forward in time.

In summary, for time-homogeneous diffusion process, we have: \[ \begin{aligned} \frac{d}{dt}p(x_0,x,t) &= -\frac{d}{dx}\{p(x_0,x,t) \mu(x)\} + \frac{1}{2}\frac{d^2}{dx^2}\{p(x_0,x,t)\sigma^2(x)\} \hspace{10mm} \text{(forward equation)} \\ \frac{d}{dt}p(x,x',t) &= \mu(x) \frac{d}{dx}p(x,x',t) + \frac{1}{2} \sigma^2(x) \frac{d^2}{dx^2}p(x,x',t) \hspace{22mm} \text{(backward equation)} \end{aligned} \] Though not to be derived, for completeness, here are the forward and backward equations corresponding to nonhomogeneous diffusion process: \[ \begin{aligned} \frac{d}{dt}p(x,s,y,t) &= -\frac{d}{dy}\{p(x,s,y,t)\mu(y, t)\} + \frac{1}{2}\frac{d^2}{dy^2}\{p(x,s,y,t)\sigma^2(y,t)\} \hspace{10mm} \text{(forward equation)} \\ \frac{d}{dt}p(x,s,y,t) &= -\mu(x,t) \frac{d}{dx}p(x,s,y,t) - \frac{1}{2}\sigma^2(x,t)\frac{d^2}{dx^2}p(x,s,y,t) \hspace{17mm} \text{(backward equation)} \end{aligned} \]

Main reference

  • An Introduction to Stochastic Processes with Applications to Biology by Linda J. S. Allen

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.2     rstudioapi_0.13  whisker_0.4      knitr_1.37      
 [5] magrittr_2.0.2   workflowr_1.7.0  R6_2.5.1         rlang_1.0.2     
 [9] fastmap_1.1.0    fansi_1.0.2      stringr_1.4.0    tools_4.1.2     
[13] xfun_0.29        utf8_1.2.2       cli_3.2.0        jquerylib_0.1.4 
[17] git2r_0.29.0     htmltools_0.5.2  ellipsis_0.3.2   yaml_2.2.2      
[21] digest_0.6.29    rprojroot_2.0.2  lifecycle_1.0.1  tibble_3.1.6    
[25] crayon_1.5.0     later_1.3.0      vctrs_0.3.8      sass_0.4.0      
[29] promises_1.2.0.1 fs_1.5.2         glue_1.6.2       evaluate_0.14   
[33] rmarkdown_2.11   stringi_1.7.6    pillar_1.7.0     compiler_4.1.2  
[37] bslib_0.3.1      jsonlite_1.8.0   httpuv_1.6.5     pkgconfig_2.0.3 

This site was created with R Markdown