R demos

Back to all R demos
Exact distributions of sums of i.i.d. rv's, and CLT
You can try out the function I used in lecture 11 to demonstrate the Central Limit Theorem.
  1. Download this file: clt.R to your computer, and save it (as clt.R)
  2. Start up R in the usual way
  3. In R, using the Source R code command (on the File menu), navigate to the appropriate folder, and select the file clt.R
  4. Run the demonstration by typing clt()
  5. The function displays the probability mass function for the sum of n i.i.d. rv's with the Bernoulli distribution with p=0.5, and n=1
  6. You can control the display with the mouse and pointer
    • You can exit the function by clicking below the horizontal axis
    • If you click in the main part of the figure, n is increased by 1
    • If you click to the left of the vertical axis, a menu is opened, and:
      • You can select a new distribution (and reset n to 1)
      • You can double the size of n
      • You can ask for the normal density with the same mean and variance to be superimposed
  7. To change the values of p or theta, run the function by typing appropriate arguments to the function - the full syntax is clt(p,theta)
  8. If you are interested in seeing how this is all done in R, and perhaps even modifying the actions, you can view the function by simply typing its name (without the () afterwards)