शुरू करेंमुफ़्त में शुरू करें

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).

यह अभ्यास पाठ्यक्रम का हिस्सा है

Generalized Linear Models in R

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Simulate 1 draw with a sample size of 100
binomial_sim <- ___
कोड संपादित करें और चलाएँ