b:head_first_statistics:geometric_binomial_and_poisson_distributions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| b:head_first_statistics:geometric_binomial_and_poisson_distributions [2019/11/07 10:26] – [What does the Poisson distribution look like?] hkimscil | b:head_first_statistics:geometric_binomial_and_poisson_distributions [2025/10/15 08:31] (current) – [e.g.,] hkimscil | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Geometric Binomial and Poisson Distributions ====== | ====== Geometric Binomial and Poisson Distributions ====== | ||
| + | 정리 | ||
| + | 기하분포, | ||
| + | \begin{align*} | ||
| + | \text{Geometric Distribution: | ||
| + | p(X = k) & = q^{k-1} \cdot p \\ | ||
| + | E\left[ X \right] & = \frac{1}{p} \\ | ||
| + | V\left[ X \right] & = \frac{q}{p^2} \\ | ||
| + | \\ | ||
| + | \text{Binomial Distribution: | ||
| + | p(X = r) & = \binom{n}{r} \cdot p^{r} \cdot q^{n-r} \\ | ||
| + | E\left[ X \right] & = {n}{p} \\ | ||
| + | V\left[ X \right] & = {n}{p}{q} \\ | ||
| + | \\ | ||
| + | \text{Poisson Distribution: | ||
| + | P(X=r) & = e^{- \lambda} \cdot \dfrac{\lambda^{r}} {r!} \\ | ||
| + | E\left[ X \right] & = \lambda \\ | ||
| + | V\left[ X \right] & = \lambda \\ | ||
| + | \end{align*} | ||
| + | |||
| ===== Geometric Distributions ===== | ===== Geometric Distributions ===== | ||
| Line 27: | Line 46: | ||
| | X | P(X=x) | | X | P(X=x) | ||
| - | | 1 | 0.2 | 0 | 1 | | + | | 1 | 0.8< |
| - | | 2 | 0.8 * 0.2 | 1 | 1 | | + | | 2 | 0.8< |
| | 3 | 0.8< | | 3 | 0.8< | ||
| | 4 | 0.8< | | 4 | 0.8< | ||
| Line 39: | Line 58: | ||
| This formula is called the **geometric distribution**. | This formula is called the **geometric distribution**. | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | order to get the first successful outcome. | + | |
| $ P(X=r) = {p \cdot q^{r-1}} $ | $ P(X=r) = {p \cdot q^{r-1}} $ | ||
| Line 55: | Line 73: | ||
| ## rather than p * q^(r-1) | ## rather than p * q^(r-1) | ||
| dgeom(x = 0:n, prob = p) | dgeom(x = 0:n, prob = p) | ||
| - | hist(dgeom(x = 0:n, prob = p)) | + | # hist(dgeom(x = 0:n, prob = p)) |
| + | barplot(dgeom(x=0: | ||
| </ | </ | ||
| Line 69: | Line 88: | ||
| [29] 0.0003868563 0.0003094850 | [29] 0.0003868563 0.0003094850 | ||
| > | > | ||
| - | > hist(dgeom(x = 0:n, prob = p))</code> | + | > # hist(dgeom(x = 0:n, prob = p)) |
| + | > barplot(dgeom(x=0: | ||
| </ | </ | ||
| - | {{: | + | < |
| - | + | {{: | |
| - | r번 시도한 후에 | + | r번 시도한 |
| - | 첫 번째 성공을 얻을 때까지 r번 이상 시도를 해야하는 | + | |
| $$ P(X > r) = q^{r} $$ | $$ P(X > r) = q^{r} $$ | ||
| - | 20번 시도 후에 어디선가 성공할 확률은? | ||
| - | 20번까지는 실패하는 확률 = $q^{r} $ | ||
| - | {{: | + | 예, 20번 시도 후에 어디선가 성공할 확률은? |
| + | Solution. | ||
| + | * 21번째 성공 + 22번째 + 23번째 + . . . . | ||
| + | * 위는 구할 수 없음 | ||
| + | * 따라서 | ||
| + | * 전체 확률이 1이고 20번째까지 성공한 확률을 1에서 빼면 원하는 확률이 됨 | ||
| + | * 1 - (1번째 성공 + 2번째 성공 + . . . + 20번째 성공) | ||
| + | * 그런데 이것은 | ||
| + | * 20번까지는 실패하는 확률 = $q^{r} $ 과 같다 | ||
| + | < | ||
| + | p <- .2 | ||
| + | q <- 1-p | ||
| + | n <- 19 | ||
| + | s <- dgeom(x = 0:n, prob = p) | ||
| + | # 20번째까지 성공할 확률을 모두 더한 확률 | ||
| + | sum(s) | ||
| + | # 따라서 아래는 20번 이후 어디서든지 간에서 성공할 확률 | ||
| + | 1-sum(s) | ||
| + | ## 혹은 (교재가 이야기하는) 20번까지 실패하는 확률 | ||
| + | q^20 | ||
| + | </ | ||
| + | < | ||
| + | > p <- .2 | ||
| + | > q <- 1-p | ||
| + | > n <- 19 | ||
| + | > s <- dgeom(x = 0:n, prob = p) | ||
| + | > # 20번째까지 성공할 확률 | ||
| + | > sum(s) | ||
| + | [1] 0.9884708 | ||
| + | > # 따라서 아래는 20번 이후 어디서든지 간에서 성공할 확률 | ||
| + | > 1-sum(s) | ||
| + | [1] 0.01152922 | ||
| + | > ## 혹은 (교재가 이야기하는) 20번까지 실패하는 확률 | ||
| + | > q^20 | ||
| + | [1] 0.01152922 | ||
| + | > | ||
| + | </ | ||
| + | {{: | ||
| + | |||
| + | 그렇다면 | ||
| r 번 이전에 성공이 있을 확률은? = r 번까지의 실패할 확률의 보수 | r 번 이전에 성공이 있을 확률은? = r 번까지의 실패할 확률의 보수 | ||
| $$ P(X \le r) = 1 - q^{r} $$ | $$ P(X \le r) = 1 - q^{r} $$ | ||
| + | |||
| + | 혹은 1번째 성공 + 2번째 성공 + . . . + r 번째 성공으로 구해도 된다 | ||
| + | < | ||
| + | # r = 20 이라고 하면 | ||
| + | p <- .2 | ||
| + | q <- 1-p | ||
| + | n <- 19 | ||
| + | s <- dgeom(x = 0:n, prob = p) | ||
| + | sum(s) | ||
| + | </ | ||
| + | |||
| + | |||
| {{: | {{: | ||
| Line 93: | Line 161: | ||
| ===== Expected value ===== | ===== Expected value ===== | ||
| - | Reminding . . . | + | X가 성공할 확률 p를 가진 Geometric distribution을 따른다 |
| + | |||
| + | Reminding . . . [[: | ||
| $E(X) = \sum x*P(X=x)$ | $E(X) = \sum x*P(X=x)$ | ||
| - | | textbook | + | | textbook |
| | r code | trial | '' | | r code | trial | '' | ||
| + | | | ||
| + | | | ||
| + | |||
| + | * 우리가 작업하고 있는 채드의 슬로프 타기 예가 얼른 이해가 안된다면 아래 workout의 예를 들어 본다. | ||
| + | |||
| + | ^ x ^ p(x) px ^ npx.0 | ||
| + | | 0 | 0.1 | 0 * 0.1 | 0.00 | 0.00 | 0.00 | | | ||
| + | | 1 | 0.15 | 1 * 0.15 | 0.15 | 0.00 + 0.15 | 0.15 | | | ||
| + | | 2 | 0.4 | 2 * 0.4 | 0.80 | 0.00 + 0.15 + 0.80 | 0.95 | | | ||
| + | | 3 | 0.25 | 3 * 0.25 | 0.75 | 0.00 + 0.15 + 0.80 + 0.75 | 1.7 | | | ||
| + | | 4 | 0.1 | 4 * 0.1 | 0.40 | 0.00 + 0.15 + 0.80 + 0.75 + 0.40 | 2.1 | = this is E(x) | | ||
| + | |||
| + | * x 일주일에 내가 갈 운동횟수 (workout frequency, 0 to 4) | ||
| + | * px 각 횟수에 대한 probability | ||
| + | * npx weighted probability | ||
| + | * plex cumulative sum of npx (to find out the below last one) | ||
| + | * sum of npx = 2.1 = mean of all = expected value of x = E(x) | ||
| + | * https:// | ||
| < | < | ||
| p <- .2 | p <- .2 | ||
| q <- 1-p | q <- 1-p | ||
| - | trial <- c(1, | + | trial <- c(1:8) |
| px <- q^(trial-1)*p | px <- q^(trial-1)*p | ||
| px | px | ||
| - | npx <- trial*(q^(trial-1))*p | + | ## npx <- trial*(q^(trial-1))*p |
| + | ## 위는 아래와 같음 | ||
| npx <- trial*px | npx <- trial*px | ||
| npx | npx | ||
| - | plex <- cumsum(trial*(q^(trial-1))*p) | + | ## plex <- cumsum(trial*(q^(trial-1))*p) |
| + | ## 위는 아래와 같음 | ||
| + | plex <- cumsum(npx) | ||
| plex | plex | ||
| sumgeod <- data.frame(trial, | sumgeod <- data.frame(trial, | ||
| Line 140: | Line 231: | ||
| > | > | ||
| </ | </ | ||
| + | |||
| + | * 아래의 예는 위의 workout 예처럼 횟수가 0-4로 정해져 있지 않고 계속 진행됨 (0-무한대) | ||
| + | * 하지만 여기서는 100 까지로 한정 (1:100) | ||
| + | * 각 지점에서의 probability = geometric probability = q^(trial-1)*p = px | ||
| + | * 각 지점에서의 weighted prob = trial * px = npx | ||
| + | * 각 단계에서의 기대값을 구하기 위한 누적합계 cumsum(npx) = plex | ||
| + | * 아래 그림에서 plex는 각 단계의 probability density를 더해온 값을 말한다. | ||
| + | * 그림이 암시하는 것처럼 오른 쪽으로 한 없이 가면서 생기는 그래프의 용적은 기대값이 된다. | ||
| + | |||
| + | | {{: | ||
| + | | {{: | ||
| + | | {{: | ||
| < | < | ||
| Line 147: | Line 250: | ||
| px <- q^(trial-1)*p | px <- q^(trial-1)*p | ||
| px | px | ||
| - | npx <- trial*(q^(trial-1))*p | + | npx <- trial*px |
| npx | npx | ||
| - | plex <- cumsum(trial*(q^(trial-1))*p) | + | ## plex <- cumsum(trial*(q^(trial-1))*p) |
| + | ## 위는 아래와 같음 | ||
| + | plex <- cumsum(npx) | ||
| plex | plex | ||
| sumgeod <- data.frame(trial, | sumgeod <- data.frame(trial, | ||
| - | round(sumgeod,3) | + | sumgeod |
| plot(npx, type=" | plot(npx, type=" | ||
| plot(plex, type=" | plot(plex, type=" | ||
| Line 158: | Line 264: | ||
| < | < | ||
| + | > | ||
| > p <- .2 | > p <- .2 | ||
| > q <- 1-p | > q <- 1-p | ||
| Line 163: | Line 270: | ||
| > px <- q^(trial-1)*p | > px <- q^(trial-1)*p | ||
| > px | > px | ||
| - | [1] 2.000000e-01 | + | [1] 2.000000e-01 |
| - | [8] 4.194304e-02 3.355443e-02 2.684355e-02 2.147484e-02 1.717987e-02 1.374390e-02 1.099512e-02 | + | [5] 8.192000e-02 6.553600e-02 5.242880e-02 4.194304e-02 |
| - | | + | [9] 3.355443e-02 2.684355e-02 2.147484e-02 1.717987e-02 |
| - | | + | |
| - | [29] 3.868563e-04 3.094850e-04 2.475880e-04 1.980704e-04 1.584563e-04 1.267651e-04 1.014120e-04 | + | |
| - | | + | |
| - | | + | |
| - | | + | [29] 3.868563e-04 3.094850e-04 2.475880e-04 1.980704e-04 |
| - | [57] 7.482888e-07 5.986311e-07 4.789049e-07 3.831239e-07 3.064991e-07 2.451993e-07 1.961594e-07 | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | [85] 1.447401e-09 1.157921e-09 9.263367e-10 7.410694e-10 5.928555e-10 4.742844e-10 3.794275e-10 | + | |
| - | | + | |
| - | | + | [57] 7.482888e-07 5.986311e-07 4.789049e-07 3.831239e-07 |
| - | > npx <- trial*(q^(trial-1))*p | + | |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | [85] 1.447401e-09 1.157921e-09 9.263367e-10 7.410694e-10 | ||
| + | | ||
| + | | ||
| + | | ||
| + | > npx <- trial*px | ||
| > npx | > npx | ||
| - | [1] 2.000000e-01 3.200000e-01 3.840000e-01 4.096000e-01 4.096000e-01 3.932160e-01 3.670016e-01 | + | [1] 2.000000e-01 3.200000e-01 3.840000e-01 4.096000e-01 |
| - | [8] 3.355443e-01 3.019899e-01 2.684355e-01 2.362232e-01 2.061584e-01 1.786706e-01 1.539316e-01 | + | [5] 4.096000e-01 3.932160e-01 3.670016e-01 3.355443e-01 |
| - | | + | [9] 3.019899e-01 2.684355e-01 2.362232e-01 2.061584e-01 |
| - | | + | |
| - | [29] 1.121883e-02 9.284550e-03 7.675228e-03 6.338253e-03 5.229059e-03 4.310012e-03 3.549422e-03 | + | |
| - | | + | |
| - | | + | |
| - | | + | [29] 1.121883e-02 9.284550e-03 7.675228e-03 6.338253e-03 |
| - | [57] 4.265246e-05 3.472060e-05 2.825539e-05 2.298743e-05 1.869645e-05 1.520236e-05 1.235804e-05 | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | [85] 1.230291e-07 9.958120e-08 8.059129e-08 6.521410e-08 5.276414e-08 4.268560e-08 3.452790e-08 | + | |
| - | | + | |
| - | | + | [57] 4.265246e-05 3.472060e-05 2.825539e-05 2.298743e-05 |
| - | > plex <- cumsum(trial*(q^(trial-1))*p) | + | |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | [85] 1.230291e-07 9.958120e-08 8.059129e-08 6.521410e-08 | ||
| + | | ||
| + | | ||
| + | | ||
| + | > ## plex <- cumsum(trial*(q^(trial-1))*p) | ||
| + | > ## 위는 아래와 같음 | ||
| + | > plex <- cumsum(npx) | ||
| > plex | > plex | ||
| - | [1] 0.200000 0.520000 0.904000 1.313600 1.723200 2.116416 2.483418 2.818962 3.120952 3.389387 | + | [1] 0.200000 0.520000 0.904000 1.313600 1.723200 2.116416 2.483418 |
| - | | + | [8] 2.818962 3.120952 3.389387 3.625610 3.831769 4.010440 4.164371 |
| - | [21] 4.760192 | + | |
| - | | + | [22] 4.800775 4.834717 4.863051 4.886663 4.906308 4.922629 4.936169 |
| - | | + | |
| - | [51] 4.999361 4.999479 4.999576 4.999655 4.999719 4.999772 4.999814 4.999849 4.999877 4.999900 | + | |
| - | | + | |
| - | [71] 4.999990 4.999992 4.999993 4.999995 4.999996 4.999997 4.999997 4.999998 4.999998 4.999998 | + | [50] 4.999215 |
| - | | + | |
| - | [91] 5.000000 5.000000 5.000000 5.000000 5.000000 5.000000 5.000000 | + | |
| + | [71] 4.999990 4.999992 4.999993 4.999995 4.999996 4.999997 4.999997 | ||
| + | | ||
| + | | ||
| + | [92] 5.000000 5.000000 5.000000 5.000000 5.000000 5.000000 5.000000 | ||
| + | | ||
| > sumgeod <- data.frame(trial, | > sumgeod <- data.frame(trial, | ||
| - | > round(sumgeod,3) | + | > sumgeod |
| - | trial px | + | trial |
| - | 1 | + | 1 |
| - | 2 | + | 2 |
| - | 3 | + | 3 |
| - | 4 | + | 4 |
| - | 5 | + | 5 |
| - | 6 | + | 6 |
| - | 7 | + | 7 |
| - | 8 | + | 8 |
| - | 9 | + | 9 |
| - | 10 | + | 10 |
| - | 11 | + | 11 |
| - | 12 | + | 12 |
| - | 13 | + | 13 |
| - | 14 | + | 14 |
| - | 15 | + | 15 |
| - | 16 | + | 16 |
| - | 17 | + | 17 |
| - | 18 | + | 18 |
| - | 19 | + | 19 |
| - | 20 | + | 20 |
| - | 21 | + | 21 |
| - | 22 | + | 22 |
| - | 23 | + | 23 |
| - | 24 | + | 24 |
| - | 25 | + | 25 |
| - | 26 | + | 26 |
| - | 27 | + | 27 |
| - | 28 | + | 28 |
| - | 29 | + | 29 |
| - | 30 | + | 30 |
| - | 31 | + | 31 |
| - | 32 | + | 32 |
| - | 33 | + | 33 |
| - | 34 | + | 34 |
| - | 35 | + | 35 |
| - | 36 | + | 36 |
| - | 37 | + | 37 |
| - | 38 | + | 38 |
| - | 39 | + | 39 |
| - | 40 | + | 40 |
| - | 41 | + | 41 |
| - | 42 | + | 42 |
| - | 43 | + | 43 |
| - | 44 | + | 44 |
| - | 45 | + | 45 |
| - | 46 | + | 46 |
| - | 47 | + | 47 |
| - | 48 | + | 48 |
| - | 49 | + | 49 |
| - | 50 | + | 50 |
| - | 51 | + | 51 |
| - | 52 | + | 52 |
| - | 53 | + | 53 |
| - | 54 | + | 54 |
| - | 55 | + | 55 |
| - | 56 | + | 56 |
| - | 57 | + | 57 |
| - | 58 | + | 58 |
| - | 59 | + | 59 |
| - | 60 | + | 60 |
| - | 61 | + | 61 |
| - | 62 | + | 62 |
| - | 63 | + | 63 |
| - | 64 | + | 64 |
| - | 65 | + | 65 |
| - | 66 | + | 66 |
| - | 67 | + | 67 |
| - | 68 | + | 68 |
| - | 69 | + | 69 |
| - | 70 | + | 70 |
| - | 71 | + | 71 |
| - | 72 | + | 72 |
| - | 73 | + | 73 |
| - | 74 | + | 74 |
| - | 75 | + | 75 |
| - | 76 | + | 76 |
| - | 77 | + | 77 |
| - | 78 | + | 78 |
| - | 79 | + | 79 |
| - | 80 | + | 80 |
| - | 81 | + | 81 |
| - | 82 | + | 82 |
| - | 83 | + | 83 |
| - | 84 | + | 84 |
| - | 85 | + | 85 |
| - | 86 | + | 86 |
| - | 87 | + | 87 |
| - | 88 | + | 88 |
| - | 89 | + | 89 |
| - | 90 | + | 90 |
| - | 91 | + | 91 |
| - | 92 | + | 92 |
| - | 93 | + | 93 |
| - | 94 | + | 94 |
| - | 95 | + | 95 |
| - | 96 | + | 96 |
| - | 97 | + | 97 |
| - | 98 | + | 98 |
| - | 99 | + | 99 |
| - | 100 | + | 100 |
| > plot(npx, type=" | > plot(npx, type=" | ||
| > plot(plex, type=" | > plot(plex, type=" | ||
| </ | </ | ||
| + | |||
| + | * 기댓값이 86번째 부터는 더이상 늘지 않고 | ||
| + | * 계산된 값을 보면 5로 수렴한다. | ||
| + | * workout 예처럼 다섯가지의 순서가 있는 것이 아니라서 | ||
| + | * 평균을 어떻게 나오나 보기 위해서 100까지 해 봤지만 | ||
| + | * 86번째 이후에는 평균값이 더 늘지 않는다 (5에서) | ||
| + | * 따라서 위의 geometric distribution에서의 기대값은 5이다. | ||
| + | |||
| {{: | {{: | ||
| {{: | {{: | ||
| + | * 그런데 이 기대값은 아래처럼 구할 수 있다. | ||
| + | * 위에서 $X \sim \text{Geo}(p)$ 일때, 기대값은 $E(X) = \dfrac{1}{p}$ | ||
| + | * 아래는 그 증명이다. | ||
| - | $X \sim Geo(p)$ 일때, | + | ===== Proof ===== |
| + | [[:Mean and Variance of Geometric Distribution# | ||
| - | $E(X) = \displaystyle \frac{1}{p}$ | ||
| - | ===== Variance ===== | + | ===== Variance |
| + | [[:Mean and Variance of Geometric Distribution# | ||
| + | 아래는 R에서의 시뮬레이션 | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| Var(X) & = & E((X-E(X))^{2}) \\ | Var(X) & = & E((X-E(X))^{2}) \\ | ||
| Line 335: | Line 482: | ||
| $E(X^{2}) = \sum {x^{2} * P(X=x)}$ | $E(X^{2}) = \sum {x^{2} * P(X=x)}$ | ||
| 왜냐하면, | 왜냐하면, | ||
| - | |||
| 이를 구한 후에 여기에서 $E[X]^{2}$ 를 빼준 값이 Var(X) | 이를 구한 후에 여기에서 $E[X]^{2}$ 를 빼준 값이 Var(X) | ||
| Line 341: | Line 487: | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | E(X)^{2} & = & (\frac{1}{p})^{2} \\ | + | E(X)^{2} & = & \left(\frac{1}{p}\right)^{2} \\ |
| & = & (5^{2}) \\ | & = & (5^{2}) \\ | ||
| & = & 25 | & = & 25 | ||
| Line 544: | Line 690: | ||
| > | > | ||
| </ | </ | ||
| - | 위에서 보듯이 plex column에 해당하는 것이 E(X^2) 부분이고 이는 45가 된다. | ||
| - | E(X)^2 은 25이므로, | ||
| - | |||
| {{: | {{: | ||
| {{: | {{: | ||
| - | $Var(X) = \displaystyle \frac{q}{p^{2}}$ | + | 위에서 보듯이 plex column에 해당하는 것이 $E(X^2)$ 부분이고 이는 45가 된다 (45에 수렴한다). 또한 언급한 것처럼 |
| + | \begin{align*} | ||
| + | Var(X) & = E(X^2) - E(X)^2 \\ | ||
| + | & = 45 - 25 \\ | ||
| + | & = 20 | ||
| + | \end{align*} | ||
| + | 일반적으로 | ||
| + | \begin{eqnarray*} | ||
| + | Var(X) = \displaystyle \frac{q}{p^{2}} | ||
| + | \end{eqnarray*} | ||
| + | |||
| + | 아래는 이를 R에서 계산해 본 것 | ||
| < | < | ||
| q/(p^2) | q/(p^2) | ||
| Line 558: | Line 712: | ||
| </ | </ | ||
| ===== Sum up ===== | ===== Sum up ===== | ||
| - | $$P(X = r) = p * q^{r-1} | + | \begin{align} |
| - | $$P(X > r) = q^{r} $$ | + | P(X = r) & = p * q^{r-1} |
| - | $$P(X \le r) = 1 - q^{r} $$ | + | P(X > r) & = q^{r} \\ |
| - | $$E(X) = \displaystyle \frac{1}{p}$$ | + | P(X \le r) & = 1 - q^{r} \\ |
| - | $$Var(X) = \displaystyle \frac{q}{p^{2}} | + | E(X) & = \displaystyle \frac{1}{p} |
| + | Var(X) | ||
| + | \end{align} | ||
| + | ===== Proof of mean and variance of geometric distribution ===== | ||
| + | $(4)$, $(5)$에 대한 증명은 [[:Mean and Variance of Geometric Distribution]] | ||
| ===== e.g., ===== | ===== e.g., ===== | ||
| <WRAP box> | <WRAP box> | ||
| Line 581: | Line 739: | ||
| $Var(X) = \displaystyle \frac{q}{p^{2}}$ | $Var(X) = \displaystyle \frac{q}{p^{2}}$ | ||
| + | < | ||
| + | > p <- .4 | ||
| + | > q <- 1-p | ||
| + | > | ||
| + | > p*q^(2-1) | ||
| + | [1] 0.24 | ||
| + | > dgeom(1, p) | ||
| + | [1] 0.24 | ||
| + | > | ||
| + | > 1-q^4 | ||
| + | [1] 0.8704 | ||
| + | > dgeom(0:3, p) | ||
| + | [1] 0.4000 0.2400 0.1440 0.0864 | ||
| + | > sum(dgeom(0: | ||
| + | [1] 0.8704 | ||
| + | > pgeom(3, p) | ||
| + | [1] 0.8704 | ||
| + | > | ||
| + | > q^4 | ||
| + | [1] 0.1296 | ||
| + | > 1-sum(dgeom(0: | ||
| + | [1] 0.1296 | ||
| + | > 1-pgeom(3, p) | ||
| + | [1] 0.1296 | ||
| + | > pgeom(3, p, lower.tail = F) | ||
| + | [1] 0.1296 | ||
| + | > | ||
| + | > 1/p | ||
| + | [1] 2.5 | ||
| + | > | ||
| + | > q/p^2 | ||
| + | [1] 3.75 | ||
| + | > | ||
| + | </ | ||
| ====== Binomial Distributions ====== | ====== Binomial Distributions ====== | ||
| + | |||
| + | - 1번의 시행에서 특정 사건 A가 발생할 확률을 p라고 하면 | ||
| + | - n번의 (독립적인) 시행에서 사건 A가 발생할 때의 확률 분포를 | ||
| + | - **이항확률분포**라고 한다. | ||
| + | 아래를 보면 | ||
| + | * 각 한문제를 맞힐 확률은 1/4, 틀릴 확률은 3/4 | ||
| + | * 3문제를 풀면서 (3번의 시행) 각 문제를 맞힐 확률 분포를 말한다. | ||
| + | |||
| {{: | {{: | ||
| {{: | {{: | ||
| Line 596: | Line 795: | ||
| {{: | {{: | ||
| - | $$P(X = r) = \Huge\text{?} \cdot 0.25^{r} \cdot 0.75^{3-r}$$ | + | $$P(X = r) = {\huge\text{?} \cdot 0.25^{r} \cdot 0.75^{3-r}} $$ |
| - | $$P(X = r) = \displaytype _{3}C_{r} \cdot 0.25^{r} \cdot 0.75^{3-r}$$ | + | $$P(X = r) = {\huge_{3}C_{r}} \cdot 0.25^{r} \cdot 0.75^{3-r}$$ |
| $_{n}C_{r}$은 n개의 사물에서 r개를 (순서없이) 고르는 방법의 수라고 할 때, 3개의 질문 중에서 한 개의 정답을 맞히는 방법은 $_{3}C_{1} = 3$ 세가지가 존재. | $_{n}C_{r}$은 n개의 사물에서 r개를 (순서없이) 고르는 방법의 수라고 할 때, 3개의 질문 중에서 한 개의 정답을 맞히는 방법은 $_{3}C_{1} = 3$ 세가지가 존재. | ||
| Line 612: | Line 811: | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| - | $$P(X = r) = \displaytype | + | $$P(X = r) = _{n}C_{r} \cdot 0.25^{r} \cdot 0.75^{n-r}$$ |
| - | $$P(X = r) = \displaytype | + | $$P(X = r) = _{n}C_{r} \cdot p^{r} \cdot q^{n-r}$$ |
| - | - You’re running a series of independent trials. | + | - You’re running a series of independent trials. |
| - | - There can be either a success or failure for each trial, and the probability of success is the same for each trial. | + | - There can be either a success or failure for each trial, and the probability of success is the same for each trial. |
| - | - There are a finite number of trials. | + | - There are a finite number of trials. |
| X가 n번의 시행에서 성공적인 결과를 얻는 수를 나타낸다고 할 때, r번의 성공이 있을 확률을 구하려면 아래 공식을 이용한다. | X가 n번의 시행에서 성공적인 결과를 얻는 수를 나타낸다고 할 때, r번의 성공이 있을 확률을 구하려면 아래 공식을 이용한다. | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | P(X = r) & = & \displaytype | + | P(X = r) & = & _{n}C_{r} \cdot p^{r} \cdot q^{n-r} \;\;\; \text{Where, |
| - | _{n}C_{r} & = & \displaytype | + | \displaystyle |
| + | \text{c.f., | ||
| + | \displaystyle _{n} P_{r} & = & \displaystyle \dfrac {n!} {(n-r)!} \\ | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| + | |||
| + | see [[: | ||
| + | |||
| p = 각 시행에서 성공할 확률 | p = 각 시행에서 성공할 확률 | ||
| Line 633: | Line 837: | ||
| ===== Expectation and Variance of ===== | ===== Expectation and Variance of ===== | ||
| + | Toss a fair coin once. What is the distribution of the number of heads? | ||
| + | * A single trial | ||
| + | * The trial can be one of two possible outcomes -- success and failure | ||
| + | * P(success) = p | ||
| + | * P(failure) = 1-p | ||
| + | |||
| + | X = 0, 1 (failure and success) | ||
| + | $P(X=x) = p^{x}(1-p)^{1-x}$ or | ||
| + | $P(x) = p^{x}(1-p)^{1-x}$ | ||
| + | |||
| + | 참고. | ||
| + | | x | 0 | 1 | | ||
| + | | p(x) | q = (1-p) | p | | ||
| + | |||
| + | When x = 0 (failure), $P(X = 0) = p^{0}(1-p)^{1-0} = (1-p)$ = Probability of failure | ||
| + | When x = 1 (success), $P(X = 1) = p^{1}(1-p)^{0} = p $ = Probability of success | ||
| + | |||
| - | {{: | + | This is called Bernoulli distribution. |
| + | * Bernoulli distribution expands to binomial distribution, | ||
| + | * Binomial distribution = The distribution of number of success in n independent Bernoulli trials. | ||
| + | * Geometric distribution = The distribution of number of trials to get the first success in independent Bernoulli trials. | ||
| $$X \sim B(1,p)$$ | $$X \sim B(1,p)$$ | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | E(X) & = & \sum{n*p(x)} \\ | + | E(X) & = & \sum{x * p(x)} \\ |
| - | & = & (1*p)+(0*q) \\ | + | & = & (0*q) + (1*p) \\ |
| & = & p | & = & p | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| Line 691: | Line 915: | ||
| n <-5 | n <-5 | ||
| # combinations of 5,2 | # combinations of 5,2 | ||
| - | c <- choose(5,2) | + | c <- choose(n,r) |
| ans1 <- c*(p^r)*(q^(n-r)) | ans1 <- c*(p^r)*(q^(n-r)) | ||
| - | ans1 | + | ans1 # or |
| + | |||
| + | choose(n, r)*(p^r)*(q^(n-r)) | ||
| + | |||
| + | dbinom(r, n, p) | ||
| + | # dbinom(2, 5, 1/4) | ||
| </ | </ | ||
| + | |||
| < | < | ||
| > p <- .25 | > p <- .25 | ||
| Line 701: | Line 932: | ||
| > n <-5 | > n <-5 | ||
| > # combinations of 5,2 | > # combinations of 5,2 | ||
| - | > c <- choose(5,2) | + | > c <- choose(n,r) |
| > ans <- c*(p^r)*(q^(n-r)) | > ans <- c*(p^r)*(q^(n-r)) | ||
| > ans | > ans | ||
| + | [1] 0.2636719 | ||
| + | > | ||
| + | > choose(n, r)*(p^r)*(q^(n-r)) | ||
| + | [1] 0.2636719 | ||
| + | > | ||
| + | > dbinom(r, n, p) | ||
| [1] 0.2636719 | [1] 0.2636719 | ||
| > | > | ||
| Line 716: | Line 953: | ||
| n <-5 | n <-5 | ||
| # combinations of 5,3 | # combinations of 5,3 | ||
| - | c <- choose(5,3) | + | c <- choose(n,r) |
| ans2 <- c*(p^r)*(q^(n-r)) | ans2 <- c*(p^r)*(q^(n-r)) | ||
| ans2 | ans2 | ||
| + | |||
| + | choose(n, r)*(p^r)*(q^(n-r)) | ||
| + | |||
| + | dbinom(r, n, p) | ||
| + | |||
| </ | </ | ||
| < | < | ||
| Line 726: | Line 968: | ||
| > n <-5 | > n <-5 | ||
| > # combinations of 5,3 | > # combinations of 5,3 | ||
| - | > c <- choose(5,3) | + | > c <- choose(n,r) |
| > ans2 <- c*(p^r)*(q^(n-r)) | > ans2 <- c*(p^r)*(q^(n-r)) | ||
| > ans2 | > ans2 | ||
| [1] 0.08789062 | [1] 0.08789062 | ||
| + | > | ||
| + | > choose(n, | ||
| + | [1] 0.08789062 | ||
| + | > | ||
| + | > dbinom(r, n, p) | ||
| + | [1] 0.08789063 | ||
| + | > | ||
| > | > | ||
| </ | </ | ||
| - | Ans 3. | + | Ans 3. 중요 |
| < | < | ||
| - | ans1 + ans2 | + | ans1 + ans2 |
| + | dbinom(2, 5, .25) + dbinom(3, 5, .25) | ||
| + | dbinom(2:3, 5, .25) | ||
| + | sum(dbinom(2: | ||
| + | pbinom(3, 5, .25) - pbinom(1, 5, .25) | ||
| </ | </ | ||
| - | < | + | < |
| + | > ans1 + ans2 | ||
| [1] 0.3515625 | [1] 0.3515625 | ||
| + | > dbinom(2, 5, .25) + dbinom(3, 5, .25) | ||
| + | [1] 0.3515625 | ||
| + | > dbinom(2:3, 5, .25) | ||
| + | [1] 0.26367187 0.08789063 | ||
| + | > sum(dbinom(2: | ||
| + | [1] 0.3515625 | ||
| + | > pbinom(3, 5, .25) - pbinom(1, 5, .25) | ||
| + | [1] 0.3515625 | ||
| + | > | ||
| </ | </ | ||
| Line 795: | Line 1058: | ||
| > </ | > </ | ||
| - | ===== Another way to see E(X) and Var(X) ===== | + | Q. 한 문제를 맞힐 확률은 1/4 이다. 총 여섯 문제가 있다고 할 때, 0에서 5 문제를 맞힐 확률은? dbinom을 이용해서 구하시오. |
| - | ==== Bernoulli Distribution ==== | + | < |
| - | Toss a fair coin once. What is the distribution of the number of heads? | + | p <- 1/4 |
| - | * A single trial | + | q <- 1-p |
| - | * The trial can be one of two possible outcomes | + | n <- 6 |
| - | * P(success) = p | + | pbinom(5, n, p) |
| - | * P(failure) = 1-p | + | 1 - dbinom(6, n, p) |
| + | sum(dbinom(0: | ||
| + | </ | ||
| + | < | ||
| + | > p <- 1/4 | ||
| + | > q <- 1-p | ||
| + | > n <- 6 | ||
| + | > pbinom(5, n, p) | ||
| + | [1] 0.9997559 | ||
| + | > 1 - dbinom(6, n, p) | ||
| + | [1] 0.9997559 | ||
| + | > sum(dbinom(0: | ||
| + | [1] 0.9997559 | ||
| + | > | ||
| + | </ | ||
| - | X = 0, 1 (failure and success) | + | 중요 . . . . |
| - | $P(X=x) = p^{x}(1-p)^{1-x}$ | + | < |
| + | # http:// | ||
| + | # ################################################################## | ||
| + | # | ||
| + | p <- 1/4 | ||
| + | q <- 1 - p | ||
| + | n <- 5 | ||
| + | r <- 0 | ||
| + | all.dens <- dbinom(0:n, n, p) | ||
| + | all.dens | ||
| + | sum(all.dens) | ||
| - | When x = 0 (failure), $P(X = 0) = p^{0}(1-p)^{1-0} = (1-p)$ = Probability of failure | + | choose(5,0)*p^0*(q^(5-0)) |
| - | When x = 1 (success), $P(X = 1) = p^{1}(1-p)^{0} = p $ = Probability of success | + | choose(5,1)*p^1*(q^(5-1)) |
| + | choose(5, | ||
| + | choose(5, | ||
| + | choose(5, | ||
| + | choose(5, | ||
| + | all.dens | ||
| - | <WRAP box> | + | choose(5,0)*p^0*(q^(5-0)) + |
| - | Bernoulli distribution expands to binomial distribution, geometric distribution, | + | |
| - | Binomial distribution = The distribution of number of success in n independent Bernoulli trials. | + | |
| - | Geometric distribution = The distribution of number of trials to get the first success in independent Bernoulli trials. | + | |
| - | </ | + | |
| - | + | | |
| - | $$P(X=x) = p^{x}(1-p)^{1-x}$$ | + | sum(all.dens) |
| - | X takes, x = 0, 1 | + | # |
| - | + | (p+q)^n | |
| - | \begin{eqnarray*} | + | # note that n = whatever, |
| - | E(X) & = & \sum_{x}xp(X=x) \\ | + | |
| - | & = & 0*p^{0}(1-p)^{1-0} + 1*p^{1}(1-p)^{1-1} \\ | + | |
| - | & = & p | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | \begin{eqnarray*} | + | |
| - | Var(X) & = & E((X-\mu)^{2}) \\ | + | |
| - | & = & \sum_{x}(x-\mu)^2p(x) | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | 한편, | + | |
| - | \begin{eqnarray*} | + | |
| - | E((X-\mu)^{2}) & = & E(X^2) - (E(X))^2 \\ | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | 위에서 | + | |
| - | \begin{eqnarray*} | + | |
| - | E(X^{2}) & = & \sum X^2 p(x) \\ | + | |
| - | & = & 0^2*p^0(1-p)^{1-0} + 1^2*p^1(1-p)^{1-1} \\ | + | |
| - | & = & p | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | zero squared probability of zero occurring | + | |
| - | one squared prob of one occurring | + | |
| - | + | ||
| - | 또한 $E(X) = p $ 임을 알고 있음 | + | |
| - | \begin{eqnarray*} | + | |
| - | Var(X) & = & E((X-\mu)^{2}) \\ | + | |
| - | & = & E(X^2) - (E(X))^2 \\ | + | |
| - | & = & p - p^2 \\ | + | |
| - | & = & p(1-p) | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | 위는 First Head Statistics 에서 $X \sim (1, 0.25)$ 에서 E(X)와 Var(X)를 구한 후 (각각, p와 pq), X가 n가지가 있다고 확장하여 np와 npq를 구한 것과 같다. 즉, 교재는 Bernoulli distribution을 이야기(설명)하지 않고, 활용하여 binomial distribution의 기대값과 분산값을 구해낸 것이다. 아래는 그 나머지. | + | |
| - | + | ||
| - | ==== Proof of E and Var ==== | + | |
| - | + | ||
| - | $E(U_{i}) = p$ and $Var(U_{i}) = p(1-p)$ or $Var(U_{i}) = p \cdot q$ | + | |
| - | + | ||
| - | $$X = U_{1} + . . . . + U_{n}$$ | + | |
| - | \begin{eqnarray*} | + | |
| - | E(X) & = & E(U_{1} + . . . + U_{n}) \\ | + | |
| - | & = & E(U_{1}) + . . . + E(U_{n}) \\ | + | |
| - | & = & p + . . . + p \\ | + | |
| - | & = & np | + | |
| - | \end{eqnarray*} | + | |
| - | + | ||
| - | \begin{eqnarray*} | + | |
| - | Var(X) & = & Var(U_{1} + . . . + U_{n}) \\ | + | |
| - | & = & Var(U_{1}) + . . . + Var(U_{n}) \\ | + | |
| - | & = & p(1-p) + . . . + p(1-p) \\ | + | |
| - | & = & np(1-p) \\ | + | |
| - | & = & npq | + | |
| - | \end{eqnarray*} | + | |
| + | </ | ||
| - | ==== From a scratch ==== | + | < |
| - | \begin{eqnarray*} | + | > # http:// |
| - | (a + b)^{m} = \sum^{m}_{y=0}{{m}\choose{y}} a^{y} b^{m-y} \\ | + | > # ################################################################## |
| - | \end{eqnarray*} | + | > # |
| - | + | > p <- 1/4 | |
| - | See youtube video clip, | + | > q <- 1 - p |
| - | {{youtube>8fqkQRjcR1M}} | + | > n <- 5 |
| - | The Binomial | + | > r <- 0 |
| + | > all.dens <- dbinom(0:n, n, p) | ||
| + | > all.dens | ||
| + | [1] 0.2373046875 0.3955078125 0.2636718750 0.0878906250 | ||
| + | [5] 0.0146484375 0.0009765625 | ||
| + | > sum(all.dens) | ||
| + | [1] 1 | ||
| + | > | ||
| + | > choose(5,0)*p^0*(q^(5-0)) | ||
| + | [1] 0.2373047 | ||
| + | > choose(5,1)*p^1*(q^(5-1)) | ||
| + | [1] 0.3955078 | ||
| + | > choose(5,2)*p^2*(q^(5-2)) | ||
| + | [1] 0.2636719 | ||
| + | > choose(5,3)*p^3*(q^(5-3)) | ||
| + | [1] 0.08789062 | ||
| + | > choose(5,4)*p^4*(q^(5-4)) | ||
| + | [1] 0.01464844 | ||
| + | > choose(5, | ||
| + | [1] 0.0009765625 | ||
| + | > all.dens | ||
| + | [1] 0.2373046875 0.3955078125 0.2636718750 0.0878906250 | ||
| + | [5] 0.0146484375 0.0009765625 | ||
| + | > | ||
| + | > choose(5, | ||
| + | + | ||
| + | + | ||
| + | + | ||
| + | + | ||
| + | + | ||
| + | [1] 1 | ||
| + | > sum(all.dens) | ||
| + | [1] 1 | ||
| + | > # | ||
| + | > (p+q)^n | ||
| + | [1] 1 | ||
| + | > # note that n = whatever, (p+q)^n = 1 | ||
| + | > | ||
| + | </ | ||
| + | ===== Proof of Binomial | ||
| + | [[:Mean and Variance | ||
| ====== Poisson Distribution ====== | ====== Poisson Distribution ====== | ||
| $$X \sim Po(\lambda)$$ | $$X \sim Po(\lambda)$$ | ||
| Line 908: | Line 1186: | ||
| For curiosity, | For curiosity, | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | \sum_{r=0}^{\infty} e^{- \lambda} \dfrac{\lambda^{r}} {r!} | + | \sum_{r=0}^{\infty} e^{- \lambda} \dfrac{\lambda^{r}} {r!} |
| + | & = & e^{- \lambda} \sum_{r=0}^{\infty} \dfrac{\lambda^{r}} {r!} \\ | ||
| & = & e^{- \lambda} \left(1 + \lambda + \dfrac{\lambda^{2}}{2!} + \dfrac{\lambda^{3}}{3!} + . . . \right) \\ | & = & e^{- \lambda} \left(1 + \lambda + \dfrac{\lambda^{2}}{2!} + \dfrac{\lambda^{3}}{3!} + . . . \right) \\ | ||
| & = & e^{- \lambda}e^{\lambda} \\ | & = & e^{- \lambda}e^{\lambda} \\ | ||
| & = & 1 | & = & 1 | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| + | |||
| + | 왜 $e^{\lambda} = \left(1 + \lambda + \dfrac{\lambda^{2}}{2!} + \dfrac{\lambda^{3}}{3!} + . . . \right)$ 인지는 [[:Taylor series]] 문서를 참조. | ||
| + | 이것이 의미하는 것은 r이 0에서 무한대로 갈 때의 확률값의 분포를 말하므로 전체 분포가 1이 됨을 의미한다. 아래 "What does the Poisson distribution look like?" 참조 | ||
| < | < | ||
| Line 923: | Line 1205: | ||
| 위의 그림은 lambda는 2, 즉 한달에 아주대학교 앞의 건널목 주변 찻길에서 교통사고가 날 횟수가 2회라고 할 때, X=3 이므로 3번 교통사고가 일어날 확률을 (P(X=3)) 묻는 문제이다. | 위의 그림은 lambda는 2, 즉 한달에 아주대학교 앞의 건널목 주변 찻길에서 교통사고가 날 횟수가 2회라고 할 때, X=3 이므로 3번 교통사고가 일어날 확률을 (P(X=3)) 묻는 문제이다. | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | P(X = 3) & = & \frac {e^{-2} * 2^{3}}{3!} \\ | + | P(X = 3) & = & e^{-2} * \frac {2^{3}}{3!} \\ |
| & = & 0.180 | & = & 0.180 | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| Line 930: | Line 1212: | ||
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | P(X=r) = e^{- \lambda} \dfrac{\lambda^{r}} {r!}, | + | P(X=r) = e^{- \lambda} \dfrac{\lambda^{r}} {r!}, |
| \end{eqnarray*} | \end{eqnarray*} | ||
| Line 951: | Line 1233: | ||
| > plot(dpois(x=1: | > plot(dpois(x=1: | ||
| > </ | > </ | ||
| + | |||
| + | 위에서 언급한 | ||
| + | |||
| + | \begin{eqnarray*} | ||
| + | \sum_{r=0}^{\infty} e^{- \lambda} \dfrac{\lambda^{r}} {r!} | ||
| + | & = & e^{- \lambda} \sum_{r=0}^{\infty} \dfrac{\lambda^{r}} {r!} \\ | ||
| + | & = & e^{- \lambda} \left(1 + \lambda + \dfrac{\lambda^{2}}{2!} + \dfrac{\lambda^{3}}{3!} + . . . \right) \\ | ||
| + | & = & e^{- \lambda}e^{\lambda} \\ | ||
| + | & = & 1 | ||
| + | \end{eqnarray*} | ||
| + | |||
| + | 에서 1 이란 이야기는 아래 그림의 그래프가 전체가 1이 됨을 의미함. 즉 위에서는 1부터 60까지 갔지만, 1부터 무한대로 하면 완전한 분포곡선이 되는데 이것이 1이라는 뜻 (가령 dpois(x=1: | ||
| + | |||
| + | |||
| [{{: | [{{: | ||
| - | lambda가 클 수록 좌우대칭의 종형분포를 이루고 ((Figure 1)), 작을 수로 오른 쪽으로 편향된 (skewed to the right) 혹은 양의방향으로 편향된(positively skewed) 분포를 ((Figure 2)) 이룬다. | + | lambda가 클 수록 좌우대칭의 종형분포를 이루고 ((Figure 1)), 작을 수록 오른 쪽으로 편향된 (skewed to the right) 혹은 양의방향으로 편향된(positively skewed) 분포를 ((Figure 2)) 이룬다. |
| < | < | ||
| Line 986: | Line 1282: | ||
| __1. What’s the probability of the machine not malfunctioning next week?__ | __1. What’s the probability of the machine not malfunctioning next week?__ | ||
| + | |||
| $\lambda = 3.4$ | $\lambda = 3.4$ | ||
| - | $ malfunctioning = 0$ | + | $\text{malfunctioning} = 0$ |
| \begin{eqnarray*} | \begin{eqnarray*} | ||
| - | P(X=0) & = & \displaytype\frac{e^{-3.4}*3.4^{0}} {0!} \\ | + | P(X=0) & = & e^{-3.4} * \frac{3.4^{0}} {0!} \\ |
| - | & = & \displaytype | + | & = & e^{-3.4} \\ |
| & = & 0.03337327 | & = & 0.03337327 | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| < | < | ||
| + | # R 에서 계산 | ||
| > e^(-3.4) | > e^(-3.4) | ||
| + | [1] 0.03337327 | ||
| + | > | ||
| + | # 혹은 | ||
| + | > dpois(0, 3.4) | ||
| [1] 0.03337327 | [1] 0.03337327 | ||
| > | > | ||
| </ | </ | ||
| + | |||
| + | 포아송 분포를 따르는 확률에서 아무것도 일어나지 않을 때의 확률은 e< | ||
| + | \begin{eqnarray*} | ||
| + | P(X=0) & = & e^{-5} * \frac{5^{0}} {0!} \\ | ||
| + | & = & e^{-5} \\ | ||
| + | & = & 0.006737947 | ||
| + | \end{eqnarray*} | ||
| + | < | ||
| + | > lamba <- 5 | ||
| + | > e <- exp(1) | ||
| + | > px.0 <- e^(-lamba) | ||
| + | > | ||
| + | > px.0 | ||
| + | [1] 0.006737947 | ||
| + | > | ||
| + | # or | ||
| + | > dpois(0,5) | ||
| + | [1] 0.006737947 | ||
| + | </ | ||
| + | |||
| + | |||
| __2. What’s the probability of the machine malfunctioning three times next week?__ | __2. What’s the probability of the machine malfunctioning three times next week?__ | ||
| Line 1006: | Line 1329: | ||
| x <- 3 | x <- 3 | ||
| e <- exp(1) | e <- exp(1) | ||
| - | ans <- ((e^(-l))*l^x)/ | + | ans <- ((e^(-l))*l^x)/ |
| </ | </ | ||
| Line 1022: | Line 1345: | ||
| > dpois(x=3, lambda=3.4) | > dpois(x=3, lambda=3.4) | ||
| [1] 0.2186172 | [1] 0.2186172 | ||
| + | </ | ||
| + | |||
| + | 마찬가지로 적어도 3번까지 고장나는 경우는 0, 1, 2, 3을 포함하므로 | ||
| + | < | ||
| + | > sum(dpois(c(0: | ||
| + | [1] 0.5583571 | ||
| + | > | ||
| </ | </ | ||
| Line 1031: | Line 1361: | ||
| \end{eqnarray*} | \end{eqnarray*} | ||
| + | [[:mean and variance of Poisson distribution]] | ||
| ===== Two Poisson distribution cases ===== | ===== Two Poisson distribution cases ===== | ||
| Line 1076: | Line 1407: | ||
| **How did Kate find the probability so quickly, and avoid the error on her calculator? | **How did Kate find the probability so quickly, and avoid the error on her calculator? | ||
| </ | </ | ||
| + | 우선 위의 문제를 binomial distribution 문제로 생각하면 답은 | ||
| + | \begin{eqnarray*} | ||
| + | P(r=15) & = & _{100}C_{15} * 0.1^{15} * 0.99^{85}\\ | ||
| + | \end{eqnarray*} | ||
| + | 라고 볼 수 있다. | ||
| \begin{eqnarray} | \begin{eqnarray} | ||
| Line 1107: | Line 1443: | ||
| > a*b*c | > a*b*c | ||
| [1] 0.03268244 | [1] 0.03268244 | ||
| + | > | ||
| + | </ | ||
| + | 위가 답이긴 하지만 limited calculator 로는 | ||
| + | x ~ b (n, p)이고 | ||
| + | b(100, 0.1)이므로 | ||
| + | n*p = 10 = lambda | ||
| + | 따라서 Pois 분포로 보는 답은 | ||
| + | lambda = 10 일때 P(r=15)값을 구하는 문제로 | ||
| + | |||
| + | \begin{eqnarray*} | ||
| + | P(r = 15) & = & e^{-10} * \frac {10^{15}}{15!} \\ | ||
| + | & = & 0.0347180 | ||
| + | \end{eqnarray*} | ||
| + | < | ||
| + | > dpois(x=15, lambda=10) | ||
| + | [1] 0.03471807 | ||
| > | > | ||
| </ | </ | ||
| Line 1223: | Line 1575: | ||
| <WRAP box> | <WRAP box> | ||
| - | 2. On average, 1 bus stops at a certain point every 15 minutes. What’s the probability that no buses will turn up in a single 15 minute interval? | + | 2. On average, 1 bus stops at a certain point every 15 minutes. What’s the probability that __<fc #ff0000>no buses</ |
| 위는 Poisson distribution 문제이므로 기대값과 분산값은 각각 lambda 값인 1 (15분마다 1대씩 버스가 온다고 한다) | 위는 Poisson distribution 문제이므로 기대값과 분산값은 각각 lambda 값인 1 (15분마다 1대씩 버스가 온다고 한다) | ||
b/head_first_statistics/geometric_binomial_and_poisson_distributions.1573089991.txt.gz · Last modified: by hkimscil
