Meir
Meir

Reputation: 21

Parameters of rbinom() in R

I'm new to R, and it's been a while for me and statistics. I don't understand what the parameters of rbinom are. What's is the difference between n (="number of observations") and size (="number of trials")?

This question is related, but I don't understand the answer there.

Thank you very much.

Upvotes: 2

Views: 6123

Answers (1)

Henry
Henry

Reputation: 6784

A binomial distribution usually has two parameters, an integer which indicates the number of attempts and so the maximum possible value (here called the size) and a success probability for each attempt between 0 and 1. The expectation is then the product of these two parameters.

For a random sample from this distribution, you are also interested in having a particular number of observations.

So in rbinom(n, size, prob) you have

  • n being the number of sample observations
  • size being the integer parameter of the binomial distribution, using 1 if you want a Bernoulli distribution
  • prob for the probability parameter of the binomial distribution

As an example, you might get

set.seed(2021)
rbinom(5, 100, 0.2)
# 19 23 22 19 21

Upvotes: 2

Related Questions