> # Binomial in R > (factorial(10)/(factorial(2)*factorial(8)))*(1/6)^2*(5/6)^8 [1] 0.29071 > dbinom(2, size=10, prob=1/6) [1] 0.29071 > n<-10 > p<-1/6 > a<-seq(0,n) > cbind(a,dbinom(a,n,p)) a [1,] 0 1.615056e-01 [2,] 1 3.230112e-01 [3,] 2 2.907100e-01 [4,] 3 1.550454e-01 [5,] 4 5.426588e-02 [6,] 5 1.302381e-02 [7,] 6 2.170635e-03 [8,] 7 2.480726e-04 [9,] 8 1.860544e-05 [10,] 9 8.269086e-07 [11,] 10 1.653817e-08 > options(scipen=999) > cbind(a,dbinom(a,n,p)) a [1,] 0 0.16150558288985 [2,] 1 0.32301116577969 [3,] 2 0.29071004920172 [4,] 3 0.15504535957425 [5,] 4 0.05426587585099 [6,] 5 0.01302381020424 [7,] 6 0.00217063503404 [8,] 7 0.00024807257532 [9,] 8 0.00001860544315 [10,] 9 0.00000082690858 [11,] 10 0.00000001653817 > cbind(a,round(dbinom(a,n,p),digits=4)) a [1,] 0 0.1615 [2,] 1 0.3230 [3,] 2 0.2907 [4,] 3 0.1550 [5,] 4 0.0543 [6,] 5 0.0130 [7,] 6 0.0022 [8,] 7 0.0002 [9,] 8 0.0000 [10,] 9 0.0000 [11,] 10 0.0000 > # Calculate CDF > pbinom(2,10,1/6) [1] 0.77523 > cbind(a,round(pbinom(a,n,p),digits=4)) a [1,] 0 0.1615 [2,] 1 0.4845 [3,] 2 0.7752 [4,] 3 0.9303 [5,] 4 0.9845 [6,] 5 0.9976 [7,] 6 0.9997 [8,] 7 1.0000 [9,] 8 1.0000 [10,] 9 1.0000 [11,] 10 1.0000 > # Calculate percentile > qbinom(.90,10,1/6) [1] 3 > rbinom(5,10,1/6) [1] 4 2 1 1 3 > rbinom(5,10,1/6) [1] 1 2 3 1 0 > # Hypergeometric > dhyper(2,13,39,5) [1] 0.27428 > b<-seq(0,5) > cbind(b,round(dhyper(b,13,39,5),digits=4)) b [1,] 0 0.2215 [2,] 1 0.4114 [3,] 2 0.2743 [4,] 3 0.0815 [5,] 4 0.0107 [6,] 5 0.0005 > cbind(b,round(phyper(b,13,39,5),digits=4)) b [1,] 0 0.2215 [2,] 1 0.6330 [3,] 2 0.9072 [4,] 3 0.9888 [5,] 4 0.9995 [6,] 5 1.0000 > # Binomial approx > cbind(b,round(dhyper(b,13,39,5),digits=4),round(dbinom(b,size=5,prob=1/4),digits=4)) b [1,] 0 0.2215 0.2373 [2,] 1 0.4114 0.3955 [3,] 2 0.2743 0.2637 [4,] 3 0.0815 0.0879 [5,] 4 0.0107 0.0146 [6,] 5 0.0005 0.0010 > # Poisson > dpois(2,lambda=2.5) [1] 0.25652 > cbind(a,round(dpois(a,2.5),digits=4)) a [1,] 0 0.0821 [2,] 1 0.2052 [3,] 2 0.2565 [4,] 3 0.2138 [5,] 4 0.1336 [6,] 5 0.0668 [7,] 6 0.0278 [8,] 7 0.0099 [9,] 8 0.0031 [10,] 9 0.0009 [11,] 10 0.0002 > cbind(a,round(dpois(a,2.5),digits=4),round(dbinom(a,1000,.0025),digits=4),round(dbinom(a,100,.025),digits=4)) a [1,] 0 0.0821 0.0818 0.0795 [2,] 1 0.2052 0.2051 0.2039 [3,] 2 0.2565 0.2567 0.2588 [4,] 3 0.2138 0.2141 0.2168 [5,] 4 0.1336 0.1337 0.1348 [6,] 5 0.0668 0.0668 0.0664 [7,] 6 0.0278 0.0277 0.0269 [8,] 7 0.0099 0.0099 0.0093 [9,] 8 0.0031 0.0031 0.0028 [10,] 9 0.0009 0.0008 0.0007 [11,] 10 0.0002 0.0002 0.0002