Harold Nelson
October 13, 2015
dbinom() returns the probabilty of the input number(s) of successes give the other arguments.
rbinom() returns a vector of length n containing random drawings from the distribution defined by the other arguments.
Compute the probability of exactly 5 successes out of 10 independent trials where the probability of success on 1 trial is .6.
#Specify arguments in order
dbinom(5,10,.6)
## [1] 0.2006581
# or alternatively, specify names in any order
dbinom(size=10,x=5,prob=.6)
## [1] 0.2006581
Compute the probability of at least 4 and at most 6 successes with 10 trials and probability of success = .6.
# Use three separate calls to dbinom().
dbinom(4,10,.6) + dbinom(5,10,.6) + dbinom(6,10,.6)
## [1] 0.5629575
# Alternatively, use a vector input for x and sum the results using the sum() function.
sum(dbinom(4:6,10,.6))
## [1] 0.5629575
We can get approximate answers to probability problems using simulated data. The first step is to create a vector of random numbers drawn from the given binomial distribution.
RB = rbinom(100000,size=10,prob=.6)
# Inspect the results
table(RB)
## RB
## 0 1 2 3 4 5 6 7 8 9 10
## 12 168 1067 4313 11025 20189 25149 21461 12006 4000 610
barplot(table(RB))
We can convert the values in RB into estimated probabilities by dividing the table by 100,000, or more generally by the sum of the counts in the table.
prob.RB = table(RB)/sum(table(RB))
# Look at the probabilities
prob.RB
## RB
## 0 1 2 3 4 5 6 7 8
## 0.00012 0.00168 0.01067 0.04313 0.11025 0.20189 0.25149 0.21461 0.12006
## 9 10
## 0.04000 0.00610
# Check that the sum of the probabilities adds up to 1.0
sum(prob.RB)
## [1] 1
We can use the values in RB directly by remembering that the mean value of a logical expression is the proportion of cases for which the logical expression is true. We can use this to repeat the exercises with above and compare the estimated probabilities with the theoretical values given by dbinom().
mean(RB == 4)
## [1] 0.11025
dbinom(4,10,.6)
## [1] 0.1114767
mean(RB >= 4 & RB <=6)
## [1] 0.56363
sum(dbinom(4:6,10,.6))
## [1] 0.5629575
Compute the probability of exactly 12 successes out of 17 trials with probability of success = .8.
dbinom(12,17,.8)
## [1] 0.1360756
Compute the probability of more than 5 successes out of 13 trials with probability of success = .2.
sum(dbinom(6:13,13,.2))
## [1] 0.03003532
A test consists of 10 true/false questions. To pass the test a student must answer at least 6 questions correctly. If a student guesses on each question, what is the probability that the student will pass the test?
sum(dbinom(6:10,10,.5))
## [1] 0.3769531
A machine has 9 identical components which function independently. The probability that a component will fail is 0.2. The machine will stop working if more than three components fail. Find the probability that the machine will be working.
1-sum(dbinom(4:9,9,.2))
## [1] 0.9143583
# or
sum(dbinom(0:3,9,.2))
## [1] 0.9143583
In a certain college, 33% of the physics majors belong to ethnic minorities. If 10 students are selected at random from the physics majors, what is the probability that no more than 6 belong to an ethnic minority?
sum(dbinom(0:6,10,.33))
## [1] 0.9814511
Find the probability of at least 2 girls in 8 births. Assume that male and female births are equally likely and that the births are independent events.
sum(dbinom(2:8,8,.5))
## [1] 0.9648438
A company purchases shipments of machine components and uses this acceptance sampling plan: Randomly select and test 22 components and accept the whole batch if there are fewer than 3 defectives. If a particular shipment of thousands of components actually has a 7% rate of defects, what is the probability that this whole shipment will be accepted?
sum(dbinom(0:2,22,.07))
## [1] 0.8032051
An airline estimates that 94% of people booked on their flights actually show up. If the airline books 71 people on a flight for which the maximum number is 69, what is the probability that the number of people who show up will exceed the capacity of the plane?
sum(dbinom(70:71,71,.94))
## [1] 0.06838378