# What is the difference between MCMC and Gauss-Legendre quadrature for integration? Can one substitute the other?

Both MCMC and Legendre quadrature are numerical methods for integration.

Method 1: MCMC $$E[g(X)] = \int f(x) g(x) \, dx$$

Method 2: Gauss-Legendre quadrature $$\int_{0.5}^{1.5} e^x \cos x \, dx$$ $$= \sum_{i=1}^{k} c_i\cdot f(x_i)$$ where $f(x)=e^x \cos x, \text{ with weights } c_i, \text{ and nods } x_i$.

Suppose I want to integrate at 3 points on, $f(x) = e^x \cos x$

3 Nods are: $x_i =[0.7746, 0, -0.7746]$
3 Weights are: $w_i = [0.5556, 0.8888888888888888, 0.5556]$

Thus, $$\int_{0.5}^{1.5} e^x \cos x \, dx = \sum_{i=1}^{3} c_i\cdot f(x_i)=1.275$$

You can also refer here: https://math.okstate.edu/people/yqwang/teaching/math4513_fall14/Notes/gaussian.pdf

So, which method to use to integrate out $\theta$?
$$f(x) = \int f(x,\theta) p(\theta) \, d\theta$$

My goal is to calculate the marginal distribution. I am using Gauss-Legendre, but can I also use MCMC? What's the difference? I am a bit confused.

• I am not familiar with Gauss- Legendre quadrature. So what exactly are the $x_i$s? Commented Jun 28, 2016 at 19:01
• @Greenparker: usually these are zeros of the interpolating family. Commented Jun 28, 2016 at 19:10
• @AlexR. I thought $c_i$s are the weights? Commented Jun 28, 2016 at 19:16
• Hi, I have updated the question with an example of Gauss-Legendre quadrature. Commented Jun 28, 2016 at 19:23
• You shouldn't use the same symbol, the lower-case $x$, to refer both to the random variable and to the variable of integration, in things like $$\operatorname{E}(g(X)) = \int f(x)g(x)\,dx$$ (where, as you see, I wrote capital $X$ for the random variable and lower-case $x$ for the variable of integration. Without distinguishing those two things, how would you understand something like $F(x) = \Pr(X\le x)$, or the difference between $F_X(3.5)$ and $F_Y(3.5)$, when those would be $F_X(x)$ and $F_Y(x)$ when $x=3.5$? $\qquad$ Commented Jun 28, 2016 at 20:54

• WIth your updated question, are you basically asking if MCMC can return what looks to be a function of $x$? Commented Jun 28, 2016 at 19:27
• Yes, I am calculating the marginal distribution: $f(x) = \int f(x,\theta) p(\theta) d\theta$ Commented Jun 28, 2016 at 19:30
• Then the answer is likely no, unless you either do repeated sampling for a grid of points $x$, or you make a variational assumption, for example by assuming $f(x,\theta)=g(x)h(\theta)$. The same applies to quadrature methods. Commented Jun 28, 2016 at 19:31