b:head_first_statistics:poisson_distribution
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
b:head_first_statistics:poisson_distribution [2025/10/07 06:51] – [Two Poisson distribution cases] hkimscil | b:head_first_statistics:poisson_distribution [2025/10/07 08:42] (current) – [Poisson Distribution] hkimscil | ||
---|---|---|---|
Line 46: | Line 46: | ||
\end{eqnarray*} | \end{eqnarray*} | ||
+ | < | ||
+ | > dpois(3, 2) | ||
+ | [1] 0.180447 | ||
+ | > | ||
+ | |||
+ | </ | ||
====== What does the Poisson distribution look like? ====== | ====== What does the Poisson distribution look like? ====== | ||
Line 232: | Line 238: | ||
& = & 0.003 | & = & 0.003 | ||
\end{eqnarray*} | \end{eqnarray*} | ||
+ | |||
+ | ====== Broken Cookies case ====== | ||
+ | <WRAP box> | ||
+ | The Case of the Broken Cookies | ||
+ | |||
+ | Kate works at the Statsville cookie factory, and her job is to make sure that boxes of cookies meet the factory’s strict rules on quality control. Kate know that **the probability that a cookie is broken is 0.1**, and her boss has asked her to find the probability that there will be 15 broken cookies in a box of 100 cookies. " | ||
+ | |||
+ | Kate picks up her calculator, but when she tries to calculate 100!, her calculator displays an error because the number is too big. “Well,” says her boss, " | ||
+ | |||
+ | Kate stares at her calculator, wondering what to do. Then she smiles. "Maybe I can leave early tonight, after all." | ||
+ | Within a minute, Kate’s calculated the probability. She’s managed to find the probability and has managed to avoid calculating 100! altogether. She picks up her coat and walks out the door. | ||
+ | |||
+ | **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} | ||
+ | X & \sim & B(n, p) \\ | ||
+ | X & \sim & Po(\lambda) | ||
+ | \end{eqnarray} | ||
+ | |||
+ | Poisson distribution을 대신 사용할 수 있으려면, | ||
+ | * B(n, p)의 경우 E(X) = np | ||
+ | * Po(lambda)의 경우 E(X) = lambda 이고 | ||
+ | |||
+ | * Var(X) = npq 이고 | ||
+ | * Var(lambda) = lambda 이다. | ||
+ | |||
+ | 따라서, 둘의 성격이 비슷하기 위해서는 npq 와 np가 같아야 한다. 따라서 q는 1이어야 하는데, 현실적으로 1일 수는 없으므로 1에 가깞고, n이 충분히 크다면 둘의 성격이 비슷해질 수 있다고 판단한다. 따라서, | ||
+ | |||
+ | * 만약 n이 충분히 크고 | ||
+ | * p가 작으면 (q가 크면) | ||
+ | * $X \sim B(n, p)$와 $Y \sim Po(np)$는 비슷할 것이다. | ||
+ | * 보통은 n > 50인 경우, p = 0.1 보다 작은 경우가 위에 해당한다. | ||
+ | |||
+ | |||
+ | < | ||
+ | > dbinom(x=15, | ||
+ | [1] 0.03268244 | ||
+ | > choose(100, 15) | ||
+ | [1] 2.533385e+17 | ||
+ | > a <- choose(100, 15) | ||
+ | > b <- .1^15 | ||
+ | > c <- .9^85 | ||
+ | > a*b*c | ||
+ | [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 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP box> | ||
+ | A student needs to take an exam, but hasn’t done any revision for it. He needs to guess the answer to each question, and the probability of getting a question right is 0.05. There are 50 questions on the exam paper. What’s | ||
+ | |||
+ | 만약에 binomial distribution 으로 계산을 한다면 | ||
+ | < | ||
+ | > dbinom(x=5, 50, 0.05) | ||
+ | [1] 0.06584064 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | Poisson distribution을 이용하라고 한다. . . | ||
+ | |||
+ | $ X \sim B(50, 0.05) $ 일 때, $P(X=5)$를 구하는 것. 이 때의 기대값 E(X)는 $ E(X) = np = 50 * .05 = 2.5 $ 이므로 위의 문제는 | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | X & \sim & Po(\lambda) \\ | ||
+ | X & \sim & Po(2.5) | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | 일 때, $P(X=5)$를 구하는 것과 같다. | ||
+ | |||
+ | < | ||
+ | [1] 0.06680094 | ||
+ | > </ | ||
+ | |||
+ | 수식을 따르면, | ||
+ | \begin{eqnarray*} | ||
+ | P(X = 5) & = & \frac {e^{-2.5} * 2.5^{5}}{5!} \\ | ||
+ | & = & 0.067 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | < | ||
+ | > n <- 50 | ||
+ | > p <- .05 | ||
+ | > q <- 1-p | ||
+ | > x <- 5 | ||
+ | > np <- n*p | ||
+ | # Poisson distribution | ||
+ | > e <- exp(1) | ||
+ | > lambda <- np | ||
+ | > lambda | ||
+ | [1] 2.5 | ||
+ | > a <- e^(-lambda) | ||
+ | > b <- lambda^x | ||
+ | > c <- factorial(x) | ||
+ | > a*b/c | ||
+ | [1] 0.06680094 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Exercise ====== | ||
+ | <WRAP box> | ||
+ | Here are some scenarios. Your job is to say which distribution each of them follows, say what the expectation and variance are, and find any required probabilities. | ||
+ | |||
+ | 1. A man is bowling. The probability of him knocking all the pins over is 0.3. If he has 10 shots, what’s the probability he’ll knock all the pins over less than three times? | ||
+ | |||
+ | Binomial distribution 을 이용한다면, | ||
+ | \begin{eqnarray*} | ||
+ | X & \sim & B(n, p) \\ | ||
+ | X & \sim & B(10, 0.3) | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | E(X) & = & np \\ | ||
+ | & = & 10 * 0.3 \\ | ||
+ | & = & 3 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | Var(X) & = & npq \\ | ||
+ | & = & 10 * 0.3 * 0.7 \\ | ||
+ | & = & 2.1 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | r을 이용한다면 '' | ||
+ | |||
+ | < | ||
+ | > pbinom(q=2, 10, 0.3) | ||
+ | [1] 0.3827828 | ||
+ | > | ||
+ | > sum(dbinom(0: | ||
+ | [1] 0.3827828 | ||
+ | > | ||
+ | |||
+ | </ | ||
+ | |||
+ | 손으로 계산을 한다고 하면, | ||
+ | $P(X=0), P(X=1), P(X=2)$를 구한 후 모두 더하여 P(X < 3)을 구한다. | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X = 0) & = & {10 \choose 0} * 0.3^0 * 0.7^{10} \\ | ||
+ | & = & 1 * 1 * 0.028 \\ | ||
+ | & = & 0.028 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X = 1) & = & {10 \choose 1} *0.3^1 * 0.7^9 \\ | ||
+ | & = & 10 * 0.3 * 0.04035 \\ | ||
+ | & = & 0.121 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X = 2) & = & {10 \choose 2} * 0.3^2 * 0.7^8 \\ | ||
+ | & = & 45 * 0.09 * 0.0576 \\ | ||
+ | & = & 0.233 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X<3) & = & P(X=0) + P(X=1) + P(X=2) \\ | ||
+ | & = & 0.028 + 0.121 + 0.233 \\ | ||
+ | & = & 0.382 | ||
+ | \end{eqnarray*} | ||
+ | </ | ||
+ | |||
+ | <WRAP box> | ||
+ | 2. On average, 1 bus stops at a certain point every 15 minutes. What’s the probability that __<fc # | ||
+ | |||
+ | 위는 Poisson distribution 문제이므로 기대값과 분산값은 각각 lambda 값인 1 (15분마다 1대씩 버스가 온다고 한다) | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X=0) & = & \frac {e^{-1}{1^0}}{0!} \\ | ||
+ | & = & \frac {e^{-1} * 1}{1} \\ | ||
+ | & = & .368 | ||
+ | \end{eqnarray*} | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > dpois(0, 1) | ||
+ | [1] 0.3678794 | ||
+ | > | ||
+ | > ppois(0, 1) | ||
+ | [1] 0.3678794 | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | <WRAP box> | ||
+ | 3. 20% of cereal packets contain a free toy. What’s the probability you’ll need to open fewer than 4 cereal packets before finding your first toy? | ||
+ | |||
+ | 이는 geometric distribution 문제이므로, | ||
+ | |||
+ | $$X \sim Geo(.2)$$ | ||
+ | |||
+ | $P(X \le 3)$ 을 구하는 문제이므로 | ||
+ | |||
+ | \begin{eqnarray*} | ||
+ | P(X \le 3) & = & 1 - q^r \\ | ||
+ | & = & 1 - 0.8^{3} \\ | ||
+ | & = & 1 - 0.512 \\ | ||
+ | & = & 0.488 | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | < | ||
+ | > sum(dgeom(0: | ||
+ | [1] 0.488 | ||
+ | > | ||
+ | > pgeom(2, 0.2) | ||
+ | [1] 0.488 | ||
+ | > | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | 기대값과 분산은 각각 $1/p$, $q/p^2$ 이므로 $5$와 $20$. | ||
+ | </ | ||
b/head_first_statistics/poisson_distribution.1759787464.txt.gz · Last modified: by hkimscil