In order to plot the graph, we use the following way:
- Divide x-axis into small intervals, with width denoted $\Delta x$.
- The integral of the normal density is approximated by summing the masses of all the tiny intervals.
R code:
Furthermore, we can plot the density graph of a given function. For instance, $p(x)=6x(1-x)$ over the interval $x\in[0,1]$. It is easy to calculate the integral: $$\int_{x=0}^{1}p(x)dx=6\cdot\int_{x=0}^{1}(x-x^2)dx=6\cdot(\frac{1}{2}x^2-\frac{1}{3}x^3)\Big|_{0}^{1}=1$$
R code:
Reference:
Kruschke, J., K. (2010). Doing Bayesian Data Analysis: A Tutorial with R and BUGS. Chapter 3.
没有评论:
发表评论