Lab3 Fitting and Plotting of Binomial Distribution & Poisson Distribution (Challenging Experiment 2 (A) and 2 (B) ) Aim
Lab3 Fitting and Plotting of Binomial Distribution & Poisson Distribution (Challenging Experiment 2 (A) and 2 (B) ) Aim
Lab3 Fitting and Plotting of Binomial Distribution & Poisson Distribution (Challenging Experiment 2 (A) and 2 (B) ) Aim
a. Binomial distribution
b. Poisson distribution
OBJECTIVE: Conceptual understanding of the role of probability as the “machinery” behind inference
Learn to fit the distribution for any data set
NOTE: To compensate 14 Lab sessions we have spilted the Challenging Experiment 2 in to Lab 3 and
Lab 4 experiemental component. Hence Binomial and Poisson Distribution will be covered in Lab 3 and
Normal distribution will be covered in Lab 4. Testing the goodness of fit with real time data will be given
in Challenging Experiment 8.
BASICS IN PROBABILITY:-
1. If you want to pick five numbers at random from the set 1:50, then you can
2. Sampling with replacement is suitable for modelling coin tosses or throws of a die.
[1] 4 4 4 1 4 6 3 5 4 2 [1] 3 3 4 3 2 1 4 2 6 3
[1] "H" "H" "H" "H" "T" "T" "T" "H" "H" "H" [1] "T" "T" "H" "H" "T" "H" "H" "H" "T" "T"
5. #Probabilities for the outcomes (chance of success) by using the prob argument to sample
6. # Combination
10 20 30
OR 10c3
3 6 5
> choose(10,3) > choose(20,6) > choose(30,5)
[1] 120 [1] 38760 [1] 142506
> choose(10,0:10)
> library(prob)
> tosscoin(1)
toss1
1 H
2 T
Test it:-
1. rolldie(2)
2. rolldie(2, nsides = 4)
start with the experiment of rolling a die, so that n = 6. construct the sample space and
generate the probs vector, and put them together with probspace.
Code:-
(vi) Sampling from Urns:-
With Replacement:-
Without Replacement
Binomial Distribution
The binomial distribution is a discrete probability distribution. It describes the
outcome of n independent trials in an experiment. Each trial is assumed to have only two
outcomes, either success or failure. If the probability of a successful trial is p, then the
probability of having x successful outcomes in an experiment of n independent trials is as
follows.
P[ X x] nx p x q n x , x 0,1,.......n
Syntax:-
For a binomial(n,p) random variable X, the R functions involve the abbreviation "binom":
>dbinom(2,size=10,prob=1/6)
[1] 0.29071
> choose(10,2)*(1/6)^2*(5/6)^8
[1] 0.29071
>plot(0:10,probs,type="h",xlim=c(0,10),ylim=c(0,0.5))
>points(0:10,probs,pch=16,cex=2)
Problem 5: Plot Binomial distribution with n=50 and P=0.33
> x=0:50
>(x,size=50,prob=0.33)
> plot(x,y,type="h")
Solution:
> dbinom(2,7,1/4) # probability of two success
[1] 0.3114624
> dbinom(0:7,7,1/4) # probabilities for whole space
[1] 1.334839e-01 3.114624e-01 3.114624e-01 1.730347e-01 5.767822e-02
[6] 1.153564e-02 1.281738e-03 6.103516e-05
>plot(0:7,dbinom(0:7,7,1/4),type="o") #shape of the Distribution
Problem 7: Suppose there are twelve multiple choice questions in an English class quiz.
Each question has five possible answers, and only one of them is correct. Find the
probability of having four or less correct answers if a student attempts to answer every
question at random.
Solution
Since only one out of five possible answers is correct, the probability of answering
a question correctly by random is 1/5=0.2. We can find the probability of having exactly 4
correct answers by random attempts as follows.
R CODE:-
> dbinom(4, size=12, prob=0.2)
[1] 0.1329
To find the probability of having four or less correct answers by random attempts, we
apply the function dbinom with x = 0,…,4.
> dbinom(0, size=12, prob=0.2) +dbinom(1, size=12, prob=0.2) + dbinom(2, size=12, prob=0
.2) + dbinom(3, size=12, prob=0.2) + dbinom(4, size=12, prob=0.2)
[1] 0.9274
Or
> sum(dbinom(x=0:4,size=12,prob=0.2))
[1] 0.9274445
or
Alternatively, we can use the cumulative probability function for binomial
distribution pbinom.
> pbinom(4, size=12, prob=0.2)
[1] 0.92744
The probability of four or less questions answered correctly by random in a twelve
question multiple choice quiz is 92.7%.
Problem 8: If 10% of the Screws produced by an automatic machine are defective, find the
probability that out of 20 screws selected at random, there are
Problem 9: Show that Binomial distribution variance is less than mean with Binomial
variable follows ( 7,1/4)
THE POISON DISTRIBUTION:
If the number of Bernoulli trials of a random experiment is fairly large and the
probability of success is small it becomes increasingly difficult to compute the binomial
probabilities. For values of n and p such that n150 and p0.05, the poisson distribution
serves as an excellent approximation to the binominal distribution.
The random variable X is said to follow the Poisson distribution if and only if
e x
p X x , x 0,1, 2,.....
x
Assumptions:-
1. Number of Bernoulli trials (n) is indefinitely large, (n )
2. The trials are independent.
3. Probability of success (p) is very small, (p 0)
= np is constant, np p
n
4. Mean and variance in poison distribution are equal
Syntax:-
Problem 1:
a. #P(x=5) with parameter 7
> dpois(x=5,lambda=7)
[1] 0.1277167
b. #P(x=0)+P(x=1)+……….+P(x=5)
> dpois(x=0:5,lambda=7)
c. > #P(x<=5)
> sum(dpois(0:5,lambda=7))
[1] 0.3007083
Or
> ppois(q=4,lambda=7,lower.tail=T)
[1] 0.1729916
d. > ppois(q=12,lambda=7,lower.tail=F)
[1] 0.02699977
Problem 2 : Check the relationship between mean and variance in Poisson distribution(4)
with n=100
> X.val=0:100
> P.val=dpois(X.val,4)
> EX=sum(X.val*P.val) #mean
> EX
[1] 4
> sum((X.val-EX)^2*P.val) #variance
[1] 4
Problem 3 : Compute Probabilities and cumulative probabilities of the values between 0 and
10 for the parameter 2 in poisson distribution.
Or
> P=data.frame (0:10,dpois(0:10,2))
> round (P,4)
Or
Problem 3: If there are twelve cars crossing a bridge per minute on average, find the
probability of having seventeen or more cars crossing the bridge in a particular minute.
Solution:-
The probability of having sixteen or less cars crossing the bridge in a particular minute is
given by the function ppois.
Hence the probability of having seventeen or more cars crossing the bridge in a minute is
in theupper tail of the probability density function.
If there are twelve cars crossing a bridge per minute on average, the probability of having
seventeen or more cars crossing the bridge in a particular minute is 10.1%.
[1] 0.9954662
[1] 0.004533806
f.
g. plot(0:10,dpois(0:10,2),type="h",xlab="y",ylab="p(y)",main="Poisson Distribution
(mu=2)")
Problem 5: # TO COMPARE BINOMIAL AND POISSON, USE SAME EXPECTED VALUE. n=8,
lambda = pn =2.4
# PLOT THE BINOMIAL PMF AND CDF FOR n=8 AND p=0.3
> pbinom(DD,8,0.3)
[1] 0.05764801 0.25529833 0.55177381 0.80589565 0.94203235 0.98870779
[7] 0.99870967 0.99993439 1.00000000
Plots:-
Problem 6. PLOT THE BINOMIAL PMF AND CDF FOR n=8 AN lambda=2.4
> DD <- 0:8
> PP <- dpois(DD,2.4); PP
[1] 0.090717953 0.217723088 0.261267705 0.209014164 0.125408499 0.060196079
[7] 0.024078432 0.008255462 0.002476639
> ppois(DD,2.4)
[1] 0.09071795 0.30844104 0.56970875 0.77872291 0.90413141 0.96432749
[7] 0.98840592 0.99666138 0.99913802
> plot(DD,PP,type="h",col=2,main="Pmf for Poisson(lambda=2.4)",xlab="x",ylab="p(x)")
> points(DD,PP,col=2); abline(h=0,col=3)
> XX <- seq(-0.01, 8.01, 0.01)
> plot(XX, ppois(XX, 2.4),type="s", ylab="F(x)",col=2,xlab="x",main="Cdf for
Poisson(lambda=2.4)");abline(h=0:1,col=4)
Plots:-
Practice Problems:-( Binomial distribution)
Problem 1: A recent national study showed that approximately 55.8% of college students have
used Google as a source in at least one of their term papers. Let X equal the number
of students in a random sample of size n = 42 who have used Google as a source:
1. How is X distributed?
2. Sketch the probability mass function (roughly).
3. Sketch the cumulative distribution function (roughly).
4. Find the probability that X is equal to 17.
5. Find the probability that X is at most 13.
6. Find the probability that X is bigger than 11.
7. Find the probability that X is at least 15.
8. Find the probability that X is between 16 and 19, inclusive
9. Give the mean of X, denoted E(X).
10. Give the variance of X.
11. Give the standard deviation of X.
12. Find E(4X + 51:324)
13. Compare mean and variance
The number of traffic accidents that occur on a particular stretch of road during a month follows a
Poisson distribution with a mean of 7.6.
1. Find the probability that less than three accidents will occur next month on
this stretch of road.
2. Find the probability of observing exactly three accidents on this stretch of
road next month.
3. Find the probability that the next two months will both result in four
accidents each occurring on this stretch of road.
4. Check the mean and variance of the poisson distribution
5. Plot the Poisson distribution and compare with binomial distribution