Session Ready
Exercise

Simulating binary data

A Bernoulli distribution is a special case of a binomial. Next, you will see how to simulate both in R and then examine the outputs to see how they are similar. Both distributions can be simulated with the random binomial function: rbinom(). rbinom() requires 3 arguments:

  • n, which is the number of draws or random numbers (i.e., an output vector of length n).
  • size, which is the number of samples per draw (i.e., the maximum value for each random number).
  • prob, which is the probability for the simulation.

To sample with a Bernoulli, you simply use size = 1.

If we take a single random draw (n = 1) from a binomial distribution with a large number of samples per draw (e.g. size = 100), we should get similar results as a taking a many samples (e.g. n = 100) with 1 sample per draw (size = 1).

Instructions 1/4
undefined XP
  • 1
  • 2
  • 3
  • 4
  • Simulate from a binomial distribution with 1 sample (n), a size (size) of 100, and a probability (p) of 0.5.