In: Statistics and Probability
Plot the probability mass function (PMF) and the cumulative distribution function (CDF) of 3 random variables following (1) binomial distribution [p,n], (2) a geometric distribution [p], and (3) Poisson distribution [?]. You have to consider two sets of parameters per distribution which can be chosen arbitrarily. The following steps can be followed
ANSWER:
R-code is given below
#Function to generate graphs for binomial(n,p)
bin=function(p,n)
{
pmf=array(0)
cdf=array(0)
#Calculating the pmf and cdf of the distribution
for(i in 0:n)
{
pmf[i]=dbinom(i,n,p)
cdf[i]=pbinom(i,n,p)
}
#PLotting the pmf and the cdf
par(mfrow=c(1,2))
plot(cdf,type="S",xlab="Support",ylab="cdf",main="Plot of
cdf")
plot(pmf,type="h",xlab="Support",ylab="pmf",main="Plot of
pmf")
}
#Calling the function
bin(0.5,10)
bin(0.8,20)
#Function to generate graphs for geom(p)
geo=function(p)
{
pmf=array(0)
cdf=array(0)
#Calculating the pmf and cdf of the distribution till 20
for(i in 0:20)
{
pmf[i]=dgeom(i,p)
cdf[i]=pgeom(i,p)
}
#PLotting the pmf and the cdf
par(mfrow=c(1,2))
plot(cdf,type="S",xlab="Support",ylab="cdf",main="Plot of
cdf")
plot(pmf,type="h",xlab="Support",ylab="pmf",main="Plot of
pmf")
}
#Calling the function
geo(0.5)
geo(0.8)
#Function to generate graphs for geom(p)
pois=function(lambda)
{
#Calculating the pmf and cdf of the distribution till 20
pmf=array(0)
cdf=array(0)
for(i in 0:20)
{
pmf[i]=dpois(i,lambda)
cdf[i]=ppois(i,lambda)
}
#Plotting the pmf and the cdf
par(mfrow=c(1,2))
plot(cdf,type="S",xlab="Support",ylab="cdf",main="Plot of
cdf")
plot(pmf,type="h",xlab="Support",ylab="pmf",main="Plot of
pmf")
}
#Calling the function
pois(4)
pois(0.5)
Plot for Bin(10,0.5)
Plot for Geom(0.4)
Plot for Poisson(4)
(OR) TRY THIS ANSWER
(1) Binomial:
R code:
#binomial[p,n]
p=c(0.01,0.5)
n=c(10,30)
x1=rbinom(11,n[1],p[1])
x2=dbinom(0:n[1],n[1],p[1])
x3=pbinom(0:n[1],n[1],p[1])
X=data.frame(cbind(x1,x2,x3))
colnames(X)=c("Column 1", "Column 2","Column 3")
y1=rbinom(11,n[1],p[2])
y2=dbinom(0:n[1],n[1],p[2])
y3=pbinom(0:n[1],n[1],p[2])
Y=data.frame(cbind(y1,y2,y3))
colnames(Y)=c("Column 1", "Column 2","Column 3")
u1=rbinom(31,n[2],p[1])
u2=dbinom(0:n[2],n[2],p[1])
u3=pbinom(0:n[2],n[2],p[1])
U=data.frame(cbind(u1,u2,u3))
colnames(U)=c("Column 1", "Column 2","Column 3")
v1=rbinom(31,n[2],p[2])
v2=dbinom(0:n[2],n[2],p[2])
v3=pbinom(0:n[2],n[2],p[2])
V=data.frame(cbind(v1,v2,v3))
colnames(V)=c("Column 1", "Column 2","Column 3")
X
Y
U
V
par(mfrow=c(2,2))
plot(0:10,x2,type="h",xlim=c(0,10),lwd=2,ylab="P(X=x)",xlab="x",main="n=10,p=0.01")
plot(0:10,y2,type="h",xlim=c(0,10),lwd=2,ylab="P(X=x)",xlab="x",main="n=10,p=0.5")
plot(0:30,u2,type="h",xlim=c(0,30),lwd=2,ylab="P(X=x)",xlab="x",main="n=30,p=0.01")
plot(0:30,v2,type="h",xlim=c(0,30),lwd=2,ylab="P(X=x)",xlab="x",main="n=30,p=0.5")
par(mfrow=c(2,2))
plot(0:10,x3,type="h",xlim=c(0,10),lwd=2,ylab="P(X=x)",xlab="x",main="n=10,p=0.01")
plot(0:10,y3,type="h",xlim=c(0,10),lwd=2,ylab="P(X=x)",xlab="x",main="n=10,p=0.5")
plot(0:30,u3,type="h",xlim=c(0,30),lwd=2,ylab="P(X=x)",xlab="x",main="n=30,p=0.01")
plot(0:30,v3,type="h",xlim=c(0,30),lwd=2,ylab="P(X=x)",xlab="x",main="n=30,p=0.5")
Output:
Binomial(10,0.01):
Column 1 Column 2 Column 3
1 0 9.043821e-01 0.9043821
2 0 9.135172e-02 0.9957338
3 0 4.152351e-03 0.9998862
4 0 1.118478e-04 0.9999980
5 0 1.977108e-06 1.0000000
6 0 2.396495e-08 1.0000000
7 0 2.017252e-10 1.0000000
8 1 1.164359e-12 1.0000000
9 0 4.410450e-15 1.0000000
10 0 9.900000e-18 1.0000000
11 0 1.000000e-20 1.0000000
Binomial(10,0.5):
Column 1 Column 2 Column 3
1 4 0.0009765625 0.0009765625
2 6 0.0097656250 0.0107421875
3 4 0.0439453125 0.0546875000
4 5 0.1171875000 0.1718750000
5 4 0.2050781250 0.3769531250
6 7 0.2460937500 0.6230468750
7 7 0.2050781250 0.8281250000
8 6 0.1171875000 0.9453125000
9 3 0.0439453125 0.9892578125
10 6 0.0097656250 0.9990234375
11 6 0.0009765625 1.0000000000
Binomial(30,0.01):
Column 1 Column 2 Column 3
1 0 7.397004e-01 0.7397004
2 1 2.241516e-01 0.9638520
3 0 3.283029e-02 0.9966823
4 1 3.095111e-03 0.9997774
5 0 2.110303e-04 0.9999884
6 0 1.108442e-05 0.9999995
7 0 4.665160e-07 1.0000000
8 2 1.615640e-08 1.0000000
9 0 4.691884e-10 1.0000000
10 0 1.158490e-11 1.0000000
11 1 2.457403e-13 1.0000000
12 0 4.513136e-15 1.0000000
13 0 7.217979e-17 1.0000000
14 1 1.009508e-18 1.0000000
15 1 1.238213e-20 1.0000000
16 0 1.334101e-22 1.0000000
17 1 1.263353e-24 1.0000000
18 1 1.050918e-26 1.0000000
19 0 7.666629e-29 1.0000000
20 0 4.890991e-31 1.0000000
21 1 2.717217e-33 1.0000000
22 0 1.306983e-35 1.0000000
23 0 5.400755e-38 1.0000000
24 0 1.897499e-40 1.0000000
25 0 5.590274e-43 1.0000000
26 0 1.355218e-45 1.0000000
27 0 2.632513e-48 1.0000000
28 0 3.939414e-51 1.0000000
29 0 4.263435e-54 1.0000000
30 0 2.970000e-57 1.0000000
31 0 1.000000e-60 1.0000000
Binomial(30,0.5):
Column 1 Column 2 Column 3
1 18 9.313226e-10 9.313226e-10
2 15 2.793968e-08 2.887100e-08
3 13 4.051253e-07 4.339963e-07
4 13 3.781170e-06 4.215166e-06
5 13 2.552290e-05 2.973806e-05
6 16 1.327191e-04 1.624571e-04
7 16 5.529961e-04 7.154532e-04
8 16 1.895986e-03 2.611440e-03
9 18 5.450961e-03 8.062401e-03
10 18 1.332457e-02 2.138697e-02
11 14 2.798160e-02 4.936857e-02
12 21 5.087564e-02 1.002442e-01
13 10 8.055309e-02 1.807973e-01
14 11 1.115351e-01 2.923324e-01
15 20 1.354354e-01 4.277678e-01
16 13 1.444644e-01 5.722322e-01
17 15 1.354354e-01 7.076676e-01
18 19 1.115351e-01 8.192027e-01
19 10 8.055309e-02 8.997558e-01
20 18 5.087564e-02 9.506314e-01
21 15 2.798160e-02 9.786130e-01
22 18 1.332457e-02 9.919376e-01
23 16 5.450961e-03 9.973886e-01
24 13 1.895986e-03 9.992845e-01
25 17 5.529961e-04 9.998375e-01
26 16 1.327191e-04 9.999703e-01
27 14 2.552290e-05 9.999958e-01
28 12 3.781170e-06 9.999996e-01
29 17 4.051253e-07 1.000000e+00
30 18 2.793968e-08 1.000000e+00
31 13 9.313226e-10 1.000000e+00
PMF:
CDF
(2) Geometric distribution:
R code:
#Gemetric[p]
p=c(0.4,0.5)
n=20
x1=rgeom(21,p[1])
x2=dgeom(0:n,p[1])
x3=pgeom(0:n,p[1])
X=data.frame(cbind(x1,x2,x3))
colnames(X)=c("Column 1", "Column 2","Column 3")
y1=rgeom(21,p[2])
y2=dgeom(0:n,p[2])
y3=pgeom(0:n,p[2])
Y=data.frame(cbind(y1,y2,y3))
colnames(Y)=c("Column 1", "Column 2","Column 3")
X
Y
par(mfrow=c(2,1))
plot(0:n,x2,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main="p=0.4")
plot(0:n,y2,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main="p=0.5")
par(mfrow=c(2,1))
plot(0:n,x3,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main="p=0.4")
plot(0:n,y3,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main="p=0.5")
Geometric(0.4):
Column 1 Column 2 Column 3
1 0 4.000000e-01 0.4000000
2 1 2.400000e-01 0.6400000
3 0 1.440000e-01 0.7840000
4 8 8.640000e-02 0.8704000
5 0 5.184000e-02 0.9222400
6 0 3.110400e-02 0.9533440
7 5 1.866240e-02 0.9720064
8 1 1.119744e-02 0.9832038
9 0 6.718464e-03 0.9899223
10 1 4.031078e-03 0.9939534
11 1 2.418647e-03 0.9963720
12 0 1.451188e-03 0.9978232
13 0 8.707129e-04 0.9986939
14 0 5.224278e-04 0.9992164
15 0 3.134567e-04 0.9995298
16 0 1.880740e-04 0.9997179
17 2 1.128444e-04 0.9998307
18 0 6.770664e-05 0.9998984
19 0 4.062398e-05 0.9999391
20 0 2.437439e-05 0.9999634
21 1 1.462463e-05 0.9999781
Geometric(0.5):
Column 1 Column 2 Column 3
1 0 5.000000e-01 0.5000000
2 1 2.500000e-01 0.7500000
3 1 1.250000e-01 0.8750000
4 0 6.250000e-02 0.9375000
5 0 3.125000e-02 0.9687500
6 2 1.562500e-02 0.9843750
7 3 7.812500e-03 0.9921875
8 0 3.906250e-03 0.9960938
9 0 1.953125e-03 0.9980469
10 0 9.765625e-04 0.9990234
11 1 4.882812e-04 0.9995117
12 5 2.441406e-04 0.9997559
13 0 1.220703e-04 0.9998779
14 0 6.103516e-05 0.9999390
15 2 3.051758e-05 0.9999695
16 4 1.525879e-05 0.9999847
17 2 7.629395e-06 0.9999924
18 0 3.814697e-06 0.9999962
19 0 1.907349e-06 0.9999981
20 3 9.536743e-07 0.9999990
21 3 4.768372e-07 0.9999995
PMF
CDF:
3. Poisson:
R code:
#Poisson[lambda]
lambda=c(0.5,1.5)
n=20
x1=rpois(21,lambda[1])
x2=dpois(0:n,lambda[1])
x3=ppois(0:n,lambda[1])
X=data.frame(cbind(x1,x2,x3))
colnames(X)=c("Column 1", "Column 2","Column 3")
y1=rpois(21,lambda[2])
y2=dpois(0:n,lambda[2])
y3=ppois(0:n,lambda[2])
Y=data.frame(cbind(y1,y2,y3))
colnames(Y)=c("Column 1", "Column 2","Column 3")
X
Y
par(mfrow=c(2,1))
plot(0:n,x2,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main=expression(lambda==0.5))
plot(0:n,y2,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main=expression(lambda==1.5))
par(mfrow=c(2,1))
plot(0:n,x3,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main=expression(lambda==0.5))
plot(0:n,y3,type="h",xlim=c(0,n),lwd=2,ylab="P(X=x)",xlab="x",main=expression(lambda==1.5))
Poisson(0.5):
Column 1 Column 2 Column 3
1 0 6.065307e-01 0.6065307
2 0 3.032653e-01 0.9097960
3 0 7.581633e-02 0.9856123
4 0 1.263606e-02 0.9982484
5 0 1.579507e-03 0.9998279
6 0 1.579507e-04 0.9999858
7 0 1.316256e-05 0.9999990
8 1 9.401827e-07 0.9999999
9 0 5.876142e-08 1.0000000
10 1 3.264523e-09 1.0000000
11 3 1.632262e-10 1.0000000
12 1 7.419371e-12 1.0000000
13 0 3.091405e-13 1.0000000
14 1 1.189002e-14 1.0000000
15 0 4.246435e-16 1.0000000
16 0 1.415478e-17 1.0000000
17 2 4.423370e-19 1.0000000
18 0 1.300991e-20 1.0000000
19 0 3.613864e-22 1.0000000
20 1 9.510169e-24 1.0000000
21 0 2.377542e-25 1.0000000
Poisson(1.5):
Column 1 Column 2 Column 3
1 0 2.231302e-01 0.2231302
2 2 3.346952e-01 0.5578254
3 0 2.510214e-01 0.8088468
4 2 1.255107e-01 0.9343575
5 1 4.706652e-02 0.9814241
6 3 1.411996e-02 0.9955440
7 4 3.529989e-03 0.9990740
8 1 7.564262e-04 0.9998304
9 2 1.418299e-04 0.9999723
10 2 2.363832e-05 0.9999959
11 0 3.545748e-06 0.9999994
12 4 4.835111e-07 0.9999999
13 0 6.043888e-08 1.0000000
14 2 6.973717e-09 1.0000000
15 1 7.471840e-10 1.0000000
16 1 7.471840e-11 1.0000000
17 1 7.004850e-12 1.0000000
18 0 6.180750e-13 1.0000000
19 2 5.150625e-14 1.0000000
20 1 4.066283e-15 1.0000000
21 2 3.049712e-16 1.0000000
PMF:
NOTE:: I HOPE YOUR HAPPY WITH MY ANSWER....***PLEASE SUPPORT ME WITH YOUR RATING...
***PLEASE GIVE ME "LIKE"...ITS VERY IMPORTANT FOR ME NOW....PLEASE SUPPORT ME ....THANK YOU