Simulating many flips of a fair coin in R

When we toss a fair coin, the result might be: $$H, H, T, H, T, \ldots$$ The proportion of the heads is $1, 1, \frac{2}{3}, 0.75, 0.6, \ldots$. We hope to simulate this process by using R. The $x$-axis is plotted on a logarithmic scale ($N=5000$ in the following example). Furthermore, we can set the probability of H when we are tossing a biased coin.

R code:







Reference:
Kruschke, J., K. (2010). Doing Bayesian Data Analysis: A Tutorial with R and BUGS. Chapter 3.



没有评论:

发表评论