# GHK algorithm

The GHK algorithm (Geweke, Hajivassiliou and Keane) is an importance sampling method for simulating choice probabilities in the multivariate probit model. These simulated probabilities can be used to recover parameter estimates from the maximized likelihood equation using any one of the usual well known maximization methods (Newton's method, BFGS, etc.). Train has well documented steps for implementing this algorithm for a multinomial probit model. What follows here will apply to the binary multivariate probit model.
Consider the case where one is attempting to evaluate the choice probability of $\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )$ where $\mathbf {y_{i}} =(y_{1},...,y_{J}),\ (i=1,...,N)$ and where we can take $j$ as choices and $i$ as individuals or observations, $\mathbf {X_{i}\beta }$ is the mean and $\Sigma$ is the covariance matrix of the model. The probability of observing choice $\mathbf {y_{i}}$ is
    ${\begin{aligned}\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )=&\int _{A_{J}}\cdots \int _{A_{1}}f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )dy_{1}^{*}\dots dy_{J}^{*}\\\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )=&\int \mathbb {1} _{y^{*}\in A}f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )d\mathbf {y} _{i}^{*}\end{aligned}}$
Where $A=A_{1}\times \cdots \times A_{J}$ and,
    $A_{j}={\begin{cases}(-\infty ,0]&y_{j}=0\\(0,\infty )&y_{j}=1\end{cases}}$
Unless $J$ is small (less than or equal to 2) there is no closed form solution for the integrals defined above (some work has been done with $J=3$). The alternative to evaluating these integrals closed form or by quadrature methods is to use simulation. GHK is a simulation method to simulate the probability above using importance sampling methods.
Evaluating $\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )=\int \mathbb {1} _{y^{*}\in A}f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )d\mathbf {y} _{i}^{*}$ is simplified by recognizing that the latent data model $\mathbf {y_{i}^{*}} =\mathbf {X_{i}\beta } +\epsilon$ can be rewritten using a Cholesky factorization, $\Sigma =CC'$. This gives $\mathbf {y_{i}^{*}} =\mathbf {X_{i}\beta } +C\eta _{i}$ where the $\eta _{i}$ terms are distributed $N(0,\mathbf {I} )$.
Using this factorization and the fact that the $\eta _{i}$ are distributed independently one can simulate draws from a truncated multivariate normal distribution using draws from a univariate random normal.
For example, if the region of truncation $\mathbf {A}$ has lower and upper limits equal to $[a,b]$ (including a,b = $\pm \infty$) then the task becomes
    ${\begin{array}{lcl}a<&y_{1}^{*}&<b\\a<&y_{2}^{*}&<b\\\vdots &\vdots &\vdots \\a<&y_{J}^{*}&<b\\\end{array}}$
Note: $\mathbf {y_{i}^{*}} =\mathbf {X_{i}\beta } +C\eta _{i}$, substituting:
    ${\begin{array}{lcl}a<&x_{1}\beta _{1}+c_{11}\eta _{1}&<b\\a<&x_{2}\beta _{2}+c_{21}\eta _{1}+c_{22}\eta _{2}&<b\\\vdots &\vdots &\vdots \\a<&x_{J}\beta _{J}+\sum _{k=1}^{J}c_{J,k}\eta _{k}&<b\\\end{array}}$
Rearranging above,
    ${\begin{array}{ccc}{\frac {a-x_{1}\beta _{1}}{c_{11}}}&<\eta _{1}<&{\frac {b-x_{1}\beta _{1}}{c_{11}}}\\{\frac {a-(x_{2}\beta _{2}+c_{21}\eta _{1})}{c_{22}}}&<\eta _{2}<&{\frac {b-(x_{2}\beta _{2}+c_{21}\eta _{1})}{c_{22}}}\\\vdots &\vdots &\vdots \\{\frac {a-(x_{J}\beta _{J}+\sum _{k=1}^{J-1}c_{J,k})}{c_{J,J}}}&<\eta _{k}<&{\frac {b-(x_{J}\beta _{J}+\sum _{k=1}^{J-1}c_{J,k})}{c_{J,J}}}\\\end{array}}$
Now all one needs to do is iteratively draw from the truncated univariate normal distribution with the given bounds above. This can be done by the inverse CDF method and noting the truncated normal distribution is given by,
    $u={\frac {\Phi ({\frac {x-\mu }{\sigma }})-\Phi ({\frac {a-\mu }{\sigma }})}{\Phi ({\frac {b-\mu }{\sigma }})-\Phi ({\frac {a-\mu }{\sigma }})}}$
Where $u$ will be a number between 0 and 1 because the above is a CDF. This suggests to generate random draws from the truncated distribution one has to solve for $x$ giving,
    $x=\sigma F^{-1}(u*(F(\beta )-F(\alpha ))+F(\alpha ))+\mu$
where $\alpha ={\frac {a-\mu }{\sigma }}$ and $\beta ={\frac {b-\mu }{\sigma }}$ and $F$ is the standard normal CDF. With such draws one can reconstruct the $\mathbf {y_{i}^{*}}$ by its simplified equation using the Cholesky factorization. These draws will be conditional on the draws coming before and using properties of normals the product of the conditional PDFs will be the joint distribution of the $\mathbf {y_{i}^{*}}$,
    $q(\mathbf {y_{i}^{*}} |\mathbf {X_{1}\beta } ,\Sigma )=q(y_{1}^{*}|\mathbf {X_{1}\beta } ,\Sigma )q(y_{2}^{*}|y_{1}^{*},\mathbf {X_{1}\beta } ,\Sigma )\dots q(y_{J}^{*}|y_{1}^{*},\dots ,y_{J-1}^{*},\mathbf {X_{1}\beta } ,\Sigma )$
Where $q(\cdot )$ is the multivariate normal distribution.
Because $y_{j}^{*}$ conditional on $y_{k},\ k<j$ is restricted to the set $A$ by the setup using the Cholesky factorization then we know that $q(\cdot )$ is a truncated multivariate normal. The distribution function of a truncated normal is,
    ${\frac {\phi ({\frac {x-\mu }{\sigma }})}{\sigma (\Phi ({\frac {b-\mu }{\sigma }})-\Phi ({\frac {a-\mu }{\sigma }}))}}$
Therefore, $y_{j}^{*}$ has distribution,
    ${\begin{aligned}q(\mathbf {y_{i}^{*}} |\mathbf {X_{i}\beta } ,\Sigma )&={\frac {{\frac {1}{c_{11}}}\phi _{1}{\Big{\frac {y_{j}^{*}-x_{1}\beta }{c_{11}}}{\Big )}}{{\Big\Phi _{1}{\Big{\frac {b-x_{1}\beta }{c_{11}}}{\Big )}-\Phi _{1}{\Big{\frac {a-x_{1}\beta }{c_{11}}}{\Big )}{\Big )}}}\times \dots \times {\frac {{\frac {1}{c_{JJ}}}\phi _{J}{\Big{\frac {y_{J}^{*}-(x_{J}\beta +c_{J1}\eta _{1}+c_{J2}\eta _{2}+\dots +c_{JJ-1}\eta _{J-1})}{c_{JJ}}}{\Big )}}{{\Big\Phi _{J}{\Big{\frac {b-(x_{J}\beta +c_{J1}\eta _{1}+c_{J2}\eta _{2}+\dots +c_{JJ-1}\eta _{J-1})}{c_{JJ}}}{\Big )}-\Phi _{J}{\Big{\frac {a-(x_{J}\beta +c_{J1}\eta _{1}+c_{J2}\eta _{2}+\dots +c_{JJ-1}\eta _{J-1}}{c_{JJ}}}{\Big )}{\Big )}}}\\&={\frac {\prod _{j=1}^{J}{\frac {1}{c_{jj}}}\phi _{j}{\Big{\frac {y_{j}^{*}-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}}{\prod _{j=1}^{J}{\Big\Phi _{j}{\Big{\frac {b-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}-\Phi {\Big{\frac {a-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}{\Big )}}}\end{aligned}}$
where $\phi _{j}$ is the standard normal pdf for choice $j$.
Because $y_{j|\{y_{k<j}^{*}\}}^{*}\sim N(\mathbf {X_{i}\beta } +\sum _{k=1}^{k<j}c_{jk}\eta _{k},c_{jj}^{2})$ the above standardization makes each term mean 0 variance 1.
Let the denominator $\prod _{j=1}^{J}\Phi _{j}{\Big{\frac {b-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}-\Phi {\Big{\frac {a-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}=\prod _{j=1}^{J}l_{jj}$ and the numerator $\prod _{j=1}^{J}{\frac {1}{c_{jj}}}\phi _{j}{\Big{\frac {y_{j}^{*}-\sum _{k=1}^{k<j}c_{jk}\eta _{k}}{c_{jj}}}{\Big )}=f_{N}(\mathbf {y_{i}^{*}} |\mathbf {X_{i}\beta } ,\Sigma )$ where $f_{N}(\cdot )$ is the multivariate normal PDF.
Going back to the original goal, to evaluate the
    ${\begin{aligned}\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )=&\int _{A_{j}}f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )dy_{j}^{*}\\\end{aligned}}$
Using importance sampling we can evaluate this integral,
    ${\begin{aligned}\Pr(\mathbf {y_{i}} |\mathbf {X_{i}\beta } ,\Sigma )=&\int _{A_{j}}f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )dy_{j}^{*}\\=&\int _{A_{j}}{\frac {f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )}{q(\mathbf {y_{i}^{*}} |\mathbf {X_{i}\beta } ,\Sigma )}}q(\mathbf {y_{i}^{*}} |\mathbf {X_{i}\beta } ,\Sigma )dy_{j}^{*}\\=&\int _{A_{j}}{\frac {f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )}{\frac {f_{N}(\mathbf {y} _{i}^{*}|\mathbf {X_{i}\beta } ,\Sigma )}{\prod _{j=1}^{J}l_{jj}}}}q(\mathbf {y_{i}^{*}} |\mathbf {X_{i}\beta } ,\Sigma )dy_{j}^{*}\\=&\mathbb {E} _{\mathbf {q} }{\Big\prod _{j=1}^{J}l_{jj}{\Big )}\\\end{aligned}}$
This is well approximated by ${\frac {1}{S}}\sum _{s=1}^{S}\prod _{j=1}^{J}l_{jj}$.