5 Simulation and Distributions
The study of statistics was founded in order to explore the properties of uncertain or random occurrences. In this chapter, we will learn how to simulate some common random phenomena. We will also learn the difference between discrete and continuous random variables, along with several very common and important distributions that describe them. Finally, we cover a brief overview of two very important theorems, the law of large numbers (LLN) and the central limit theorem (CLT), which describe what happen to 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()
for the Poisson distribution. - Use
rnorm()
,dnorm()
,pnorm()
, andqnorm()
for the Normal distribution. - Use
runif()
,dunif()
,punif()
, andqunif()
for the Uniform distribution. Use
rexp()
,dexp()
,pexp()
, andqexp()
for the Exponential distribution.Use
replicate()
to run the same random calculation over and over many times.