
89Random Variables, Distributions, Moments, and Statistics
3.9.8 coMparinG saMple anD theoretical Distributions: exaMple binoMial
Generate a random sample from a binomial with p = 0.2. Verify that sample mean is approximately
equal to expected value. Run hist on the object you generated to demonstrate that the histogram
indeed looks like a binomial pmf.
Generate random sample of size 100 and store it in a vector object
>sambinom100 <- rbinom(100,3,0.2)
The arithmetic average (sample mean) of these 100 numbers is about 0.6 but not exactly. For example,
> mean(sambinom100)
[1] 0.57
Of course, it depends on the sample. Now plot histogram of the random ...