5 Exploring Distributions of Random Variables Through Simulation
One goal of statistics is to quantify the uncertainty that arises when trying to summarize “random variables” – outcomes that have random variation from one realization to another. In this chapter, we will learn how to use simulation to mimic the processes that generate random variables and their distributions. We will consider both discrete and continuous random variables, and some of the most commonly encountered distributions of each type. We will also use simulation to gain some intuition about two important theorems: the law of large numbers (LLN) and the central limit theorem (CLT). These theorems describe the behavior of sample means of random variables, as well as the overall distribution of a collection of random variables, in the long run.
Learning Objectives
- Learn how to simulate simple random events, like coin flips and dice rolls.
- Learn about common discrete distributions.
- Learn about common continuous distributions.
- Learn about the law of large numbers and the central limit theorem.
Useful Functions
- Use
sample()
to generate random samples from a finite set of elements. Use
set.seed()
to set a random seed for reproducible results.- Use
rbinom()
to sample from the Bernoulli and binomial distributions. - Use
dbinom()
to calculate the probability density function (PDF) of the Bernoulli/binomial distributions. - Use
pbinom()
to calculate the cumulative distribution function (CDF) of the Bernoulli/binomial distributions. Use
qbinom()
to calculate the quantile function of the Bernoulli/binomial distributions.- Use
rpois()
,dpois()
,ppois()
, andqpois()
, analogous functions for the Poisson distribution. - Use
rnorm()
,dnorm()
,pnorm()
, andqnorm()
, analogous functions for the normal distribution. - Use
runif()
,dunif()
,punif()
, andqunif()
, analogous functions for the uniform distribution. Use
rexp()
,dexp()
,pexp()
, andqexp()
, analogous functions for the exponential distribution.Use
replicate()
to run the same random calculation over and over many times.