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 [2025/10/06 20:51] – [Proof of E and Var from Bernoulli Distribution] hkimscil | b:head_first_statistics:geometric_binomial_and_poisson_distributions [2025/10/06 23:43] (current) – [e.g.,] hkimscil | ||
---|---|---|---|
Line 797: | Line 797: | ||
===== 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)$$ | ||
Line 857: | Line 877: | ||
c <- choose(n, | c <- choose(n, | ||
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) | ||
</ | </ | ||
+ | |||
< | < | ||
> p <- .25 | > p <- .25 | ||
Line 868: | Line 894: | ||
> 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 | ||
> | > | ||
> | > | ||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Ans 2. | Ans 2. | ||
Line 883: | Line 920: | ||
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 894: | Line 936: | ||
> 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 959: | Line 1022: | ||
> </ | > </ | ||
- | ===== 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 | + | |
- | X = 0, 1 (failure and success) | + | 1 - dbinom(6, n, p) |
- | $P(X=x) = p^{x}(1-p)^{1-x}$ or | + | </ |
- | $P(x) = p^{x}(1-p)^{1-x}$ | + | < |
+ | > p <- 1/4 | ||
+ | > q <- 1-p | ||
+ | > n <- 6 | ||
+ | > pbinom(5, n, p) | ||
+ | [1] 0.9997559 | ||
+ | > 1 - dbinom(6, n, p) | ||
+ | [1] 0.9997559 | ||
- | 참고. | + | </ |
- | | 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 | + | < |
+ | # http:// | ||
+ | # ################################################################## | ||
+ | # | ||
+ | p <- 1/4 | ||
+ | q <- 1 - p | ||
+ | n <- 5 | ||
+ | r <- 0 | ||
+ | all.dens <- dbinom(0:n, n, p) | ||
+ | all.dens | ||
+ | sum(all.dens) | ||
- | <WRAP box> | + | choose(5, |
- | Bernoulli distribution expands to binomial distribution, geometric distribution, etc. | + | choose(5,1)*p^1*(q^(5-1)) |
- | Binomial distribution = The distribution of number of success in n independent Bernoulli trials. | + | choose(5,2)*p^2*(q^(5-2)) |
- | Geometric distribution = The distribution of number of trials to get the first success in independent Bernoulli trials. | + | choose(5, |
- | </ | + | choose(5, |
+ | choose(5, | ||
+ | all.dens | ||
- | $P(X=x) = p^{x}(1-p)^{1-x}$ or | + | choose(5,0)*p^0*(q^(5-0)) + |
- | $P(x) = p^{x}(1-p)^{1-x}$ | + | choose(5, |
- | X takes, x = 0, 1 | + | |
+ | choose(5, | ||
+ | choose(5, | ||
+ | | ||
+ | sum(all.dens) | ||
+ | # | ||
+ | (p+q)^n | ||
+ | # note that n = whatever, (p+q)^n = 1 | ||
- | ==== Expectation and Variance value ==== | + | </ |
- | \begin{eqnarray*} | + | |
- | E(X) & = & \sum_{x}xP(x) \\ | + | |
- | & = & 0*p^{0}(1-p)^{1-0} + 1*p^{1}(1-p)^{1-1} | + | |
- | & = & p \\ | + | |
- | \\ | + | |
- | 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*} | + | > # http:// |
- | 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 | + | > p <- 1/4 |
- | \end{eqnarray*} | + | > q <- 1 - p |
- | + | > n <- 5 | |
- | zero squared probability of zero occurring | + | > r <- 0 |
- | one squared prob of one occurring | + | > all.dens <- dbinom(0:n, n, p) |
- | + | > all.dens | |
- | 또한 $E(X) = p $ 임을 알고 있음 | + | [1] 0.2373046875 0.3955078125 0.2636718750 0.0878906250 |
- | \begin{eqnarray*} | + | [5] 0.0146484375 0.0009765625 |
- | Var(X) & = & E((X-\mu)^{2}) \\ | + | > sum(all.dens) |
- | & = & E(X^2) - (E(X))^2 \\ | + | [1] 1 |
- | & = & p - p^2 \\ | + | > |
- | & = & p(1-p) | + | > choose(5,0)*p^0*(q^(5-0)) |
- | \end{eqnarray*} | + | [1] 0.2373047 |
- | + | > choose(5,1)*p^1*(q^(5-1)) | |
- | 위는 First Head Statistics 에서 $X \sim (1, 0.25)$ 에서 E(X)와 Var(X)를 구한 후 (각각, p와 pq), X가 n가지가 있다고 확장하여 np와 npq를 구한 것과 같다. 즉, 교재는 Bernoulli distribution을 이야기(설명)하지 않고, 활용하여 binomial distribution의 기대값과 분산값을 구해낸 것이다. | + | [1] 0.3955078 |
- | + | > choose(5,2)*p^2*(q^(5-2)) | |
- | ==== extension of Bernoulli Distribution ==== | + | [1] 0.2636719 |
- | + | > choose(5,3)*p^3*(q^(5-3)) | |
- | $E(U_{i}) = p$ and $Var(U_{i}) = p(1-p)$ or $Var(U_{i}) = p \cdot q$ | + | [1] 0.08789062 |
- | + | > choose(5,4)*p^4*(q^(5-4)) | |
- | $$X = U_{1} + . . . . + U_{n}$$ | + | [1] 0.01464844 |
- | \begin{eqnarray*} | + | > choose(5,5)*p^5*(q^(5-5)) |
- | E(X) & = & E(U_{1} + . . . + U_{n}) \\ | + | [1] 0.0009765625 |
- | & = & E(U_{1}) + . . . + E(U_{n}) \\ | + | > all.dens |
- | & = & p + . . . + p \\ | + | [1] 0.2373046875 0.3955078125 0.2636718750 0.0878906250 |
- | & = & np | + | [5] 0.0146484375 0.0009765625 |
- | \end{eqnarray*} | + | > |
- | + | > choose(5,0)*p^0*(q^(5-0)) | |
- | \begin{eqnarray*} | + | + choose(5,1)*p^1*(q^(5-1)) + |
- | Var(X) & = & Var(U_{1} + . . . + U_{n}) \\ | + | + choose(5,2)*p^2*(q^(5-2)) + |
- | & = & Var(U_{1}) + . . . + Var(U_{n}) \\ | + | + choose(5,3)*p^3*(q^(5-3)) + |
- | & = & p(1-p) + . . . + p(1-p) \\ | + | + choose(5,4)*p^4*(q^(5-4)) + |
- | & = & np(1-p) \\ | + | + choose(5, |
- | & = & npq | + | [1] 1 |
- | \end{eqnarray*} | + | > sum(all.dens) |
- | + | [1] 1 | |
- | + | > # | |
- | ===== From a scratch (Proof of Binomial Expected Value) ===== | + | > (p+q)^n |
+ | [1] 1 | ||
+ | > # note that n = whatever, (p+q)^n = 1 | ||
+ | > | ||
+ | </ | ||
+ | ===== Proof of Binomial Expected Value and Variance | ||
[[:Mean and Variance of Binomial Distribution|이항분포에서의 기댓값과 분산에 대한 수학적 증명]], Mathematical proof of Binomial Distribution Expected value and Variance | [[:Mean and Variance of Binomial Distribution|이항분포에서의 기댓값과 분산에 대한 수학적 증명]], Mathematical proof of Binomial Distribution Expected value and Variance | ||
====== Poisson Distribution ====== | ====== Poisson Distribution ====== |
b/head_first_statistics/geometric_binomial_and_poisson_distributions.1759751481.txt.gz · Last modified: by hkimscil