Professional Documents
Culture Documents
21bce0427 VL2022230503921 Ast02
21bce0427 VL2022230503921 Ast02
21bce0427 VL2022230503921 Ast02
NAME: Chethan N V
REG.NO: 21BCE0427
Slot: L5+L6
Code:
#Name: Chethan N V
> #Reg No: 21BCE0427
>
>
> p=1/3 #Proportion of population that consumes alcohol
> n=20 #Number of individuals investigated by each
investigator
> N=1000 #Total number of investigators
>
> # (a) How are individuals distributed?
> n_p=N*n #Total number of individuals in the population
> n_c=round(p*n_p) #Number of individuals who consume
alcohol
> n_c
[1] 6667
>
>
> # (b) Probability function for consumers
> p_c=dbinom(0:n, size=n, prob=p)
> p_c
[1] 3.007287e-04 3.007287e-03 1.428461e-02 4.285383e-02
9.106440e-02
[6] 1.457030e-01 1.821288e-01 1.821288e-01 1.479796e-01
9.865310e-02
[11] 5.425920e-02 2.466327e-02 9.248728e-03 2.845762e-03
7.114406e-04
[16] 1.422881e-04 2.223252e-05 2.615590e-06 2.179659e-07
1.147189e-08
[21] 2.867972e-10
>
>
> # Plot probability function
> plot(0:n, p_c, type="h", lwd=2, xlab="Number of consumers",
ylab="Probability", main="Probability Function for Consumers")
>
> # (c) Cumulative distribution function
> c_p_c=pbinom(0:n, size=n, prob=p)
> c_p_c
[1] 0.0003007287 0.0033080153 0.0175926266 0.0604464606
0.1515108579
[6] 0.2972138936 0.4793426882 0.6614714828 0.8094511284
0.9081042255
[11] 0.9623634289 0.9870267032 0.9962754310 0.9991211934
0.9998326340
[16] 0.9999749222 0.9999971547 0.9999997703 0.9999999882
0.9999999997
[21] 1.0000000000
>
>
> # Plot cumulative distribution function
> plot(0:n, c_p_c, type="s", lwd=2, xlab="Number of
consumers", ylab="Cumulative Probability", main="Cumulative
Distribution Function for Consumers")
>
>
> # (d) Expected number of investigators
> # (i) Three people were consumers
> expected_3_consumers <- N * pbinom(3, size=n, prob=p,
lower.tail=FALSE)
> e3c=N*pbinom(3, size=n, prob=p, lower.tail=FALSE)
> e3c
[1] 939.5535
>
>
> # (ii) Four people or less were consumers
> expected_4_or_less_consumers <- N * pbinom(4, size=n,
prob=p)
> e4c=N*pbinom(4, size=n, prob=p)
> e4c
[1] 151.5109
>
>
> # (iii) 6 to 8 people were consumers
> # (iii) 6 to 8 people were consumers
> e6to8=N * diff(pbinom(c(5,8), size=n, prob=p))
> e6to8
[1] 512.2372
>
>
> # (iv) At least 15 people were consumers
> e15ormore=N*pbinom(14, size=n, prob=p, lower.tail=FALSE)
> e15ormore
[1] 0.167366
>
>
>
Screenshots:
Aim: To Fit a binomial distribution
Code:
> #Name: Chethan N V
>
> x=c(0,1,2,3,4,5,6)
> f=c(275,72,30,7,5,2,1)
> n=sum(f)
> p=sum(x*f)/(n*max(x))
> y=binom(x,n,p)
> y=dbinom(x,n,p)
> y
> plot(x,y)
Screenshots: