blue-sky
blue-sky

Reputation: 53806

Binomial probabilty invocation with R

At a car hire service 50% of cars are returned on time. A sample of 20 car hires is studied. Is this the correct R invocation of dbinom in order to calculate all 20 cars are returned on time ? :

dbinom(x=20, size=20, prob=0.5)

Upvotes: 1

Views: 45

Answers (1)

duckmayr
duckmayr

Reputation: 16920

Yes.

We can check against what we know the answer to be (0.5^20, since 20 choose 20 is 1 and (0.5^20)*(0.5^(20-20)) = 0.5^20):

dbinom(x=20, size=20, prob=0.5)
# [1] 9.536743e-07

0.5^20
# [1] 9.536743e-07

From help("dbinom"):

x, q vector of quantiles.
...
size number of trials (zero or more).
prob probability of success on each trial.

So here, x is our quantile (what is the probability there were 20 successes?), size is our number of trials (a sample of 20), and prob is the probability of success in each one (there is a 1/2 chance each car is returned timely).

Upvotes: 3

Related Questions