library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#dbinom


x=6
n=13
p=0.7

dbinom(x,size=n,prob=p)
## [1] 0.0441524
# plotting graph
x=0:n
plot(x,dbinom(x,size=n,prob=p),main="Probability mass function for Bin(13,0.7)")

#pbinom
x=9
n=13
p=0.7
pbinom(x,n,p)
## [1] 0.5793944
#plotting graph
x=0:n
plot(x,pbinom(x,n,p), type="s",main="Cummulative Dsitribution function for Bin(13,0.7)")

#pbinom
plot(0:26,pbinom(0:26,51,1/2),type="s")

pbinom(0:26,51,1/2)
##  [1] 4.440892e-16 2.309264e-14 5.893064e-13 9.837464e-12 1.208154e-10
##  [6] 1.164008e-09 9.161814e-09 6.057629e-08 3.433559e-07 1.694414e-06
## [11] 7.368858e-06 2.851906e-05 9.901973e-05 3.105217e-04 8.845986e-04
## [16] 2.300655e-03 5.486781e-03 1.204645e-02 2.443695e-02 4.595727e-02
## [21] 8.038980e-02 1.312188e-01 2.005310e-01 2.879247e-01 3.898840e-01
## [26] 5.000000e-01 6.101160e-01
#qbinom

qbinom(0.25,51,1/2)
## [1] 23
#rbinom
rbinom(8,150,0.4)
## [1] 59 61 63 58 58 61 70 55
#Que
pbinom(4,12,0.20)
## [1] 0.9274445
#Que
dbinom(6,10,3/5)
## [1] 0.2508227
pbinom(9,10,3/5)
## [1] 0.9939534
#dhyper
dhyper(x=2,m=4,n=5,k=6)
## [1] 0.3571429
plot(0:2,dhyper(x=0:2,m=4,n=5,k=6),type="S")

#que
phyper(q=3,m=5,n=8,k=4)
## [1] 0.993007
phyper(q=2,m=5,n=8,k=4,lower.tail = FALSE)
## [1] 0.1188811
1-phyper(q=2,m=5,n=8,k=4,lower.tail = TRUE)
## [1] 0.1188811
#que
qhyper(0.90,5,11,4)
## [1] 2
#que
dhyper(x=2,m=6,n=4,k=3)
## [1] 0.5
#que
dhyper(x=2,m=6,n=9,k=5)
## [1] 0.4195804
#que
phyper(q=2,m=10,n=40,k=5)
## [1] 0.9517397
#que
dhyper(x=0,m=3,n=17,k=5)
## [1] 0.3991228
dhyper(x=2,m=3,n=17,k=5)
## [1] 0.1315789
#que
dhyper(x=4,m=7,n=3,k=4)
## [1] 0.1666667
phyper(q=2,m=3,n=7,k=4)
## [1] 0.9666667
#POisson

#que
dpois(0,lambda = 1000*0.001)
## [1] 0.3678794
#que
dpois(2,lambda = 1)
## [1] 0.1839397
#que
den=dhyper(x=1:20,70,30,20)

data.frame(red=1:20,den)%>%
  mutate(red14=ifelse(red==14,"x=14","other"))%>%
  ggplot(aes(x=factor(red),den, fill=red14))+geom_col()

den=dhyper(x=1:6,m=4,n=5,k=6)

data.frame(daffodil=1:6,den)%>%
  mutate(daffodil2=ifelse(daffodil==4,"x=4","other"))%>%
  ggplot(aes(x=factor(daffodil),den,fill=daffodil2))+geom_col()