Vous êtes sur la page 1sur 9

r pract ical 2: Discret e Dist ribut ions

Name: Chinmay Mokal

Quest ion 1

runif(10,1,15)

3.40678012976423 · 13.2870323909447 · 5.20188196701929 · 1.71352159045637 · 1.04411573754624 · 11.6359448879957 · 8.43743295921013 · 9.04572813492268 · 7.83165869582444 · 12.6728583308868

rbinom(10,2,0.2)

0· 0· 0· 2· 1· 0· 0· 1· 1· 1

rgeom(10,0.73)

0· 0· 0· 1· 0· 0· 0· 0· 0· 0

rnbinom(10,5,0.3)

4 · 4 · 8 · 6 · 3 · 16 · 4 · 10 · 20 · 6

rpois(10,4)

3 · 10 · 2 · 3 · 4 · 1 · 7 · 1 · 3 · 3

Quest ion 2

x=c(66,96,34,54,10,37,95,87,65,25,94,83,54,11,35)

sample(x,10,replace=TRUE)

83 · 34 · 35 · 25 · 96 · 66 · 94 · 54 · 34 · 83

sample(x,10,replace=FALSE)

10 · 11 · 96 · 87 · 37 · 35 · 34 · 83 · 54 · 54

Quest ion 3

(A)

x=0:10;n=10
u=dunif(x,1,n)
d=data.frame(x,u);d
plot(x,u,"h")

A data.frame: 11 × 2
x u

<int> <dbl>

0 0.0000000

1 0.1111111

2 0.1111111

3 0.1111111

4 0.1111111

5 0.1111111

6 0.1111111

7 0.1111111

8 0.1111111

9 0.1111111

10 0.1111111

x=0:10;n=10
cu=punif(x,1,n)
cu1=round(cu,4)
d1=data.frame(x,cu1);d1
plot(x,cu1,"s",main='Uniform Distribution(N=10)')

A data.frame: 11 ×
2
x cu1

<int> <dbl>

0 0.0000

1 0.0000

2 0.1111

3 0.2222

4 0.3333

5 0.4444

6 0.5556

7 0.6667

8 0.7778

9 0.8889

10 1.0000

(B)

x=0:10;n=10;p=0.2
db=dbinom(x,n,p)
d=data.frame(x,p)
d
plot(x,db,"h")
c1=pbinom(x,10,p)
cb1=round(c1,4)
plot(x,cb1,"s")

A data.frame: 11
×2
x p

<int> <dbl>

0 0.2

1 0.2

2 0.2

3 0.2

4 0.2

5 0.2

6 0.2

7 0.2

8 0.2

9 0.2

10 0.2

x=0:10;n=10;p=0.5
db=dbinom(x,n,p)
d=data.frame(x,p)
d
plot(x,db,"h")
c2=pbinom(x,n,p)
cb2=round(c2,4)
cb2
plot(x,cb2,"s")

A data.frame: 11
×2
x p

<int> <dbl>

0 0.5

1 0.5

2 0.5

3 0.5

4 0.5

5 0.5

6 0.5

7 0.5

8 0.5

9 0.5

10 0.5
0.001 · 0.0107 · 0.0547 · 0.1719 · 0.377 · 0.623 · 0.8281 · 0.9453 · 0.9893 · 0.999 · 1

x=0:10;n=10;p=0.8
db=dbinom(x,n,p)
d=data.frame(x,p)
d
plot(x,db,"h")
c3=pbinom(x,n,p)
cb3=round(c3,4)
plot(x,cb3,"s")
A data.frame: 11
×2
x p

<int> <dbl>

0 0.8

1 0.8

2 0.8

3 0.8

4 0.8

5 0.8

6 0.8

7 0.8

8 0.8

9 0.8

10 0.8

(C)

m=1;x=0:10
p=dpois(x,m)
d=data.frame(x,p)
d
plot(x,p,"h")
p1=ppois(x,m)
cp1=round(p1,4)
cp1
plot(x,cp1,"s")

A data.frame: 11 × 2
x p

<int> <dbl>

0 3.678794e-01

1 3.678794e-01

2 1.839397e-01

3 6.131324e-02

4 1.532831e-02

5 3.065662e-03

6 5.109437e-04

7 7.299195e-05

8 9.123994e-06

9 1.013777e-06

10 1.013777e-07
0.3679 · 0.7358 · 0.9197 · 0.981 · 0.9963 · 0.9994 · 0.9999 · 1 · 1 · 1 · 1

m=5;x=0:10
p=dpois(x,m)
d=data.frame(x,p)
d
plot(x,p,"h")
p2=ppois(x,m)
cp2=round(p2,4)
cp2
plot(x,cp2,"s")
A data.frame: 11 × 2
x p

<int> <dbl>

0 0.006737947

1 0.033689735

2 0.084224337

3 0.140373896

4 0.175467370

5 0.175467370

6 0.146222808

7 0.104444863

8 0.065278039

9 0.036265577

10 0.018132789
0.0067 · 0.0404 · 0.1247 · 0.265 · 0.4405 · 0.616 · 0.7622 · 0.8666 · 0.9319 · 0.9682 · 0.9863

m=10;x=0:10
p=dpois(x,m)
d=data.frame(x,p)
d
plot(x,p,"h")
p3=ppois(x,m)
cp3=round(p3,4)
cp3
plot(x,cp3,"s")

A data.frame: 11 × 2
x p

<int> <dbl>

0 4.539993e-05

1 4.539993e-04

2 2.269996e-03

3 7.566655e-03

4 1.891664e-02

5 3.783327e-02

6 6.305546e-02

7 9.007923e-02

8 1.125990e-01

9 1.251100e-01

10 1.251100e-01
0 · 5e-04 · 0.0028 · 0.0103 · 0.0293 · 0.0671 · 0.1301 · 0.2202 · 0.3328 · 0.4579 · 0.583

(D)

p=0.2;x=0:10
bp=dgeom(x,p)
d=data.frame(x,bp)
d
plot (x,bp,"s")
cp=pgeom(x,p)
cp1=round(cp,4)
d1=data.frame(x,cp1)
plot(x,cp1,"s")
A data.frame: 11 × 2
x bp

<int> <dbl>

0 0.20000000

1 0.16000000

2 0.12800000

3 0.10240000

4 0.08192000

5 0.06553600

6 0.05242880

7 0.04194304

8 0.03355443

9 0.02684355

10 0.02147484

p=0.8;x=0:10
bp=dgeom(x,p)
d=data.frame(x,bp)
d
plot (x,bp,"s")
cp=pgeom(x,p)
cp2=round(cp,4)
d2=data.frame(x,cp2)
plot(x,cp2,"s")

A data.frame: 11 × 2
x bp

<int> <dbl>

0 8.000e-01

1 1.600e-01

2 3.200e-02

3 6.400e-03

4 1.280e-03

5 2.560e-04

6 5.120e-05

7 1.024e-05

8 2.048e-06

9 4.096e-07

10 8.192e-08

(E)

p=0.3;r=5;x=0:10
bp=dnbinom(x,r,p)
d=data.frame(x,bp)

plot(x,bp,"s") 
cp=pnbinom(x,r,p) 
cpl=round(cp,4)
d1=data.frame(x,cpl) 
plot(x,cpl,"s")
A data.frame: 11 × 2
x bp

<int> <dbl>

0 0.00243000

1 0.00850500

2 0.01786050

3 0.02917215

4 0.04084101

5 0.05145967

6 0.06003628

7 0.06603991

8 0.06934191

9 0.07011237

10 0.06871013

p=0.3;r=10;x=0:10
bp=dnbinom(x,r,p)
d=data.frame(x,bp)

plot(x,bp,"s") 
cp=pnbinom(x,r,p) 
cpl=round(cp,4)
d1=data.frame(x,cpl) 
plot(x,cpl,"s")

A data.frame: 11 × 2
x bp

<int> <dbl>

0 0.0000059049

1 0.0000413343

2 0.0001591371

3 0.0004455838

4 0.0010137030

5 0.0019868580

6 0.0034770014

7 0.0055632023

8 0.0082752634

9 0.0115853688

10 0.0154085405

p=0.3;r=40;x=0:10
bp=dnbinom(x,r,p)
d=data.frame(x,bp)

plot(x,bp,"s") 
cp=pnbinom(x,r,p) 
cpl=round(cp,4)
d1=data.frame(x,cpl) 
plot(x,cpl,"s")
A data.frame: 11 × 2
x bp

<int> <dbl>

0 1.215767e-21

1 3.404146e-20

2 4.884950e-19

3 4.787251e-18

4 3.602406e-17

5 2.219082e-16

6 1.165018e-15

7 5.359084e-15

8 2.203923e-14

9 8.227980e-14

10 2.822197e-13

(F)

n=100;p=0.02;x=0:n
bp=dbinom(x,n,p) 
d=data.frame("x-values"=x,"probabilities"=bp) 

plot(x,bp,"s")
cp=pbinom(x,n,p) 
cpl=round(cp,4) 
d1=data.frame(x,cpl) 
plot(x,cpl,"s")
A data.frame: 101 × 2
x.values probabilities

<int> <dbl>

0 1.326196e-01

1 2.706522e-01

2 2.734139e-01

3 1.822759e-01

4 9.020799e-02

5 3.534680e-02

6 1.142159e-02

7 3.130114e-03

8 7.426036e-04

9 1.549196e-04

10 2.877078e-05

11 4.804026e-06

12 7.271400e-07

13 1.004526e-07

14 1.273962e-08

15 1.490622e-09

16 1.616108e-10

17 1.629689e-11

18 1 533607e 12

m=2;x=0:10
bp=dpois(x,m) 
d=data.frame(x,bp) 

plot(x,bp,"s") 
cp=ppois(x,m) 
cpl=round(cp,4) 
d1=data.frame(x,cpl) 
plot(x,cpl,"s")

A data.frame: 11 × 2
x bp

<int> <dbl>

0 1.353353e-01

1 2.706706e-01

2 2.706706e-01

3 1.804470e-01

4 9.022352e-02

5 3.608941e-02

6 1.202980e-02

7 3.437087e-03

8 8.592716e-04

9 1.909493e-04

10 3.818985e-05

Quest ion 4

x=0:5;f=c(221,148,55,28,6,9)
m=sum(f*x)/sum(f)
var=(sum(f*x*x)/sum(f))-m*m
p=m/var;q=1--p;r=m*p/q
px=dnbinom(x,r,p)
px1=round(px,5)
ef=sum(f)*px1
ef1=round(ef,0)
d=data.frame(x,f,"exp.freq."=ef1)
d
plot(f,ef1,pch="x");abline(0,1)

A data.frame: 6 × 3
x f exp.freq.

<int> <dbl> <dbl>

0 221 412

1 148 44

2 55 9

3 28 2

4 6 0

5 9 0
Quest ion 5

x=0:6
f=c (6,54,150,200,152,85,18)
m=sum(x*f)/sum(f)
n=max(x)
p=m/n; q=1-p
px=dbinom (x, n, p)
px1=round(px,4)
ef=sum(f)*px1
ef1=round(ef,0)
d=data.frame(x, f,"expected frequency"=ef1)
d
plot (f, ef1, pch="x"); abline (0,1)

A data.frame: 7 × 3
x f expected.frequency

<int> <dbl> <dbl>

0 6 8

1 54 51

2 150 140

3 200 206

4 152 171

5 85 76

6 18 14

Quest ion 6

x=0:5
f=c (132,146,59,29,8,2)
m=sum(x*f)/sum(f)
px=dpois (x, m)
px=round(px,4)
ef=sum(f)*px
ef1=round(ef,0)
d=data.frame(x, f,"expected frequency"=ef)
d
plot (f, ef1, pch="x"); abline (0,1)

A data.frame: 6 × 3
x f expected.frequency

<int> <dbl> <dbl>

0 132 132.2016

1 146 138.1800

2 59 72.2296

3 29 25.1544

4 8 6.5800

5 2 1.3912

Vous aimerez peut-être aussi