The sample space of Bernoulli experiment has only two possible outcomes: Failure or Success. pbinom(y=r,n,p) returns the probability P(Y<=r) where Y ~ Binom(n,p), where r= trial, n= size and p= probability
Question 1.
Fourty percent of workers in Newtown support tax reform. Take a random sample of twelve supporters (with replacement, to ensure independence); what is the probability that exactly ten of the twelve support the proposal?
# in order to get the exactly 10 we need to subtract P(9,12)
pbinom(10,12,0.4)-pbinom(9,12,0.4)
## [1] 0.002491417
Defining a Combination Function for Mathematical Solutions
Com = function(n, x) {
factorial(n) / factorial(n-x) / factorial(x)
}
#Mathematical Solution
Com(12,10)*(4/10)^10*(6/10)^2
## [1] 0.002491417
Question 2.
A coin is tossed three times, Find the all possibilities?
#pbinom(y,n,p) returns the probability Y<=y therefore:
# The possibility of 0 heads (3 Tails)is:
pbinom(0,3,0.5)
## [1] 0.125
# The possibility of 1 head (2 Tails)is:
pbinom(1,3,0.5)- pbinom(0,3,0.5)
## [1] 0.375
# The possibility of 2 heads (1 Tail)is:
pbinom(2,3,0.5)- pbinom(1,3,0.5)
## [1] 0.375
# The possibility of 3 heads (0 Tails)is:
pbinom(3,3,0.5)- pbinom(2,3,0.5)
## [1] 0.125
#Mathematical Solution
# The possibility of 0 heads (3 Tails)is:
Com(3,3)*(1/2)^3*(1/2)^0
## [1] 0.125
# The possibility of 1 head (2 Tails)is:
Com(3,2)*(1/2)^2*(1/2)^1
## [1] 0.375
# The possibility of 2 heads (1 Tail)is:
Com(3,1)*(1/2)^1*(1/2)^2
## [1] 0.375
# The possibility of 3 heads (0 Tails)is:
Com(3,0)*(1/2)^0*(1/2)^3
## [1] 0.125
Question 3.
A test consists of 10 multiple choice questions with five choices for each question. As an experiment, you GUESS on each and every answer without even reading the questions. What is the probability of getting exactly 6 questions correct on this test?
#n=10; r=6, p =0.2
pbinom(6,10,0.2)- pbinom(5,10,0.2)
## [1] 0.005505024
#Mathematical Solution
Com(10,6)*(1/5)^6*(4/5)^4
## [1] 0.005505024
Question 4. At a certain intersection, the light for eastbound traffic is red for 15 seconds, yellow for 5 seconds, and green for 30 seconds. Find the probability that out of the next eight eastbound cars that arrive randomly at the light, exactly three will be stopped by a red light.
# n=8, r=3, prob =15/50
pbinom(3,8,0.3)- pbinom(2,8,0.3)
## [1] 0.2541218
#Mathematical Solution
Com(8,3)*(15/50)^3*(35/50)^5
## [1] 0.2541218
Question 5.
A pizza parlor is running a promotion. Everyone who comes to the restaurant gets to spin a wheel that gives them a 10% chance of getting a free pizza. If you go with five friends, and each of you spins the wheel, what is the chance of winning at least one pizza for your group?
# the possibility of getting at least 1 pizza is to find zero chance and subtract from 1.
1-pbinom(0,6,0.1)
## [1] 0.468559
#Mathematical Solution
1 - Com(6,0)*(9/10)^6
## [1] 0.468559
It is the same as the binomial except we dont have a fix number of trials, we keep going trying until we get a success (or failure depends on the situation).
pgeom(k,p) returns P(Y<=k), when Y ~ Geom(p), where k is number of failures
Question 6. Suppose that you play a game that involves rolling a fair die. You will play the game until you roll a six, what is the probability that you win the game at the 4th roll?
# Rolling a dice and get a succes at 4th roll means there are 3 failures
# pgeom(k,p) where k is the number of failures until success and p is the success probability (or vice versa)
pgeom(3,1/6)-pgeom(2,1/6)
## [1] 0.09645062
#Mathematical Solution
#P(Y=k) = p*(1-p)^k
#P(Y=4) =
1/6*(5/6)^3
## [1] 0.09645062
Question 7. A quiz consists of ten multiple choice questions with choices (a) and (b) for each. If an unprepared student marks answers at random, what is the probability of the getting first seven answers are wrong?
# So the 8th answer is correct: Total 8 trial and 7 failures(k=7), 1 success.
pgeom(7,1/2)-pgeom(6,1/2)
## [1] 0.00390625
#Mathematical Solution
1/2*(1/2)^7
## [1] 0.00390625
Question 8. Team A has a 40% chance of beating Team B in a single game. What is the probability that team A loses all the games until the seventh game of the series?
# So the 8th answer is correct: Total 7 trial and 6 failures(k=6), 1 success.
pgeom(6,4/10) - pgeom(5,4/10)
## [1] 0.0186624
#Mathematical Solution
4/10*(6/10)^6
## [1] 0.0186624
Question 9. Suppose 10% of the U.S. population reside in the state of California. What is the probability of randomly selecting more than 5 people before selecting a person who resides in CA?
#We can find the all probability of selecting 6 people (number of failures: k=5) and subtract from 1.
1-pgeom(5,1/10)
## [1] 0.531441
#MAthematical Solution
1 -(1/10+(9/10)*(1/10)+(9/10)^2*1/10+(9/10)^3*1/10+(9/10)^4*1/10+(9/10)^5*1/10)
## [1] 0.531441
Question 10.
You play a game of chance that you can either win or lose (there are no other possibilities) until you lose. Your probability of losing is 0.57. What is the probability that it takes five games until you lose?
# The goal is play the game until you lose so(the number of success: k=4 and p=0.57)
pgeom(4,0.57)-pgeom(3,0.57)
## [1] 0.01948717
#MAthematical Solution
0.57*(0.43)^4
## [1] 0.01948717
The hypergeometric distribution is a probability distribution that is very similar to the binomial distribution without replacement.
phyper(m,M,N,n) function returns P(Y<=k) where Y ~ HG(M,N,n)
m the number of the balls drawn from the M urn (returns 0 to m) M the number of white balls in the urn. N the number of black balls in the urn. n the total number of balls drawn from the urns
Question 12.
A group of 6 female managers and 7 male managers apply for an assignment. A random sample of 5 people is drawn at random without replacement. What is the probability of choosing 2 female and 3 male?
phyper(2,6,7,5)-phyper(1,6,7,5)
## [1] 0.4079254
#Mathematical Solution
Com(6,2)*Com(7,3)/Com(13,5)
## [1] 0.4079254
Question 13. There are 7 balls in a urn, they are identical except color, 3 blue and 4 yellow. You drawn three balls from the urn and set it aside. What is the probability of having 2 balls in the same color ?
phyper(2,3,4,3)-phyper(1,3,4,3) + phyper(2,4,3,3)-phyper(1,4,3,3)
## [1] 0.8571429
#Mathematical Solution
(Com(3,2)*Com(4,1)/Com(7,3)) + (Com(4,2)*Com(3,1)/Com(7,3))
## [1] 0.8571429
Question 14. In a class of 24 seniors, 8 students got accepted from MIT, 5 students got accepted from Brown, and 11 students got accepted from Ohio State. If a group of 10 seniors is chosen at random (a) What is the probability that exactly two of the group got accepted from Brown? (b) What is the probability that none of the group got accepted from Brown?
phyper(2,5,19,10) - phyper(1,5,19,10)
## [1] 0.3853755
#Mathematical Solution
(Com(5,2)*Com(19,8)/Com(24,10))
## [1] 0.3853755
phyper(10,19,5,10) - phyper(9,19,5,10)
## [1] 0.04710145
#Mathematical Solution
(Com(5,0)*Com(19,10)/Com(24,10))
## [1] 0.04710145
Question 15. In a certain community there are two ethnic groups: A and B. Suppose there is a school with 24 kids from group A, and 15 from group B. Five children are to be chosen to represent the school at a community event. If the kids are chosen at random what is the proportion of times that there are three from A and two from B?
(phyper(3,24,15,5) - phyper(2,24,15,5))
## [1] 0.3691141
#Mathematical Solution
(Com(24,3)*Com(15,2)/Com(39,5))
## [1] 0.3691141
The Poisson distribution is useful for modeling counts. Counts of natural events suc as number of hurricanes or earthquakes in a given timespan are often modeled with Poisson distribution.
\(P(Y=k) = \frac{e^{k} * \lambda^{k}}{k!}\)
Pois(k,lambda) will return P(Y<=k) when Y~ Pois(lambda)
Question 16. The classical example of the Poisson distribution is the number of Prussian soldiers accidentally killed by horse-kick, due to being the first example of the Poisson distribution’s application to a real-world large data set.
Ten army corps were observed over 20 years, for a total of 200 observations, and 122 soldiers were killed by horse-kick over that time period.
What is the probability of observing one death in a given year?
#k=1, lambda (average)=122/200 = 0.61
ppois(1,0.61)-ppois(0,0.61)
## [1] 0.331444
#Mathematical Solution
#P(Y=1) ; lambda =0.61
(exp(-0.61)*0.61^1)/factorial(1)
## [1] 0.331444
Question 17. Births in a hospital occur randomly at an average rate of 1.8 births per hour. a. What is the probability of observing 4 births in a given hour at the hospital?
#k=4, lambda=1.8
ppois(4,1.8)-ppois(3,1.8)
## [1] 0.07230173
#Mathematical Solution
#P(Y=4) ; lambda =1.8
(exp(-1.8)*1.8^4)/factorial(4)
## [1] 0.07230173
#k>1, lambda=1.8
1-ppois(1,1.8)
## [1] 0.5371631
#Mathematical Solution
# 1- P(Y=1)-P(Y=0) and lambda= 1.8
1-(exp(-1.8)*1.8^1)/factorial(1)-(exp(-1.8)*1.8^0)/factorial(0)
## [1] 0.5371631
Question 18.
Suppose there are on average 54 volcanoes that erupt each year somewhere on Earth. On about how many days per year only two volcanoes may erupt?
#k=0, lambda=54/365= 0.14
365* (ppois(2,0.14)-ppois(1,0.14))
## [1] 3.109694
#Mathematical Solution
# P(Y=0) and lambda= 54
365*((exp(-0.14)*0.14^2)/factorial(2))
## [1] 3.109694
Question 19.
The number of daily on-the-job accidents at a factory, follows a Poisson distribution with mean .26. If we randomly select two days from last year, what is the probability that on three days there were no accidents? (Assume independence.)
#k=3, lambda= 0.26
(ppois(3,0.26)-ppois(2,0.26))
## [1] 0.002258667
#Mathematical Solution
# P(Y=0) and lambda= 54
((exp(-0.26)*0.26^3)/factorial(3))
## [1] 0.002258667
Question 20. Suppose disease A occurs with incidence 1.4 per million and disease B occurs with incidence 2.3 per million. Statistics are compiled, in which these diseases are not distinguished, but simply are all called cases of disease AB. What is the probability that a city of 1 million people has at least 4 cases of AB?
#k>3, lambda= 3.7
(1-ppois(3,3.7))
## [1] 0.5058468
#Mathematical Solution
# 1-P(Y=0)-P(Y=1)-P(Y=2)-P(Y=3) and lambda= 3.7
1-(exp(-3.7)*3.7^0)/factorial(0)- (exp(-3.7)*3.7^1)/factorial(1)-
(exp(-3.7)*3.7^2)/factorial(2)- (exp(-3.7)*3.7^3)/factorial(3)
## [1] 0.5058468