Bayesian Statistics in simple English

ph
Admin (토론 | 기여)님의 2017년 6월 14일 (수) 22:27 판 (→‎3.2 Bayes Theorem)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
이동: 둘러보기, 검색

읽은 글은 Bayesian Statistics explained to Beginners in Simple English

baysian inference가 뭔가 찾아보다가 발견한 문서.



1. Frequentist Statistics

2. The Inherent Flaws in Frequentist Statistics

여기 p-value랑 C.I.(confidence interval)나오는데, 이런 기본용어 설명이 여기가 기가 막히다. 이것도 따로 빼둔다.

3. Bayesian Statistics

3.1 Conditional Probability

Bayes theorem is built on top of conditional probability and lies in the heart of Bayesian Inference.

3.2 Bayes Theorem

\(\Large P(A|B) = \frac{\Large P(B|A_i) P(A_i) }{\Large \sum_{i=1}^n P(B|A_i)P(A_i)} \)

denominator는 normalizer

4. Bayesian Inference

prior × likelihood = posterior × evidence

posterior \(\propto\) prior × likelihood

4.1. Bernoulli likelihood function

\(\Large P(y|θ)=θ^y(1-θ)^{1-y}\)

\( y =\{0, 1\}, θ = (0, 1) \)

\(y=1\) means 'head of a coin', \(θ\) means fairness of a coin.

so,

$$ P(y_1, y_2, ... , y_n | θ) = \prod_1^n P(y_i|θ) $$ $$ P(z,N|θ) = θ^z (1-θ)^{N-z} $$ where z is a number of heads and N is a number of flips.

이게 prior다. \(P(\theta)\)

4.2. Prior Belief Distribution

위키의 prior probability도 읽어보면 좋을것 같지만 길어서 미룬다;;

beta(\(P(p;α,β)=\frac{p^{α-1} (1-p)^{β-1}}{B(α,β)}, B \)는 그냥 normalizer.)는 binomial의 conjugate prior이기도 하다.

beta dist 위키를 보면, 아래가 핵심

Beta distributions provide a family of prior probability distributions for binomial distributions in Bayesian inference.

binomial의 prior가 곧 beta라는 얘기.(과정은 여기. 아래 퍼둠. Conjugate prior라고 했으니까 binomial 또한 beta의 family다.)

$${\displaystyle {\begin{aligned}P(s,f\mid q=x)&={s+f \choose s}x^{s}(1-x)^{f},\\P(x)&={x^{\alpha -1}(1-x)^{\beta -1} \over \mathrm {B} (\alpha ,\beta )},\\P(q=x\mid s,f)&={\frac {P(s,f\mid x)P(x)}{\int P(s,f\mid x)P(x)dx}}\\&={{{s+f \choose s}x^{s+\alpha -1}(1-x)^{f+\beta -1}/\mathrm {B} (\alpha ,\beta )} \over \int _{y=0}^{1}\left({s+f \choose s}y^{s+\alpha -1}(1-y)^{f+\beta -1}/\mathrm {B} (\alpha ,\beta )\right)dy}\\&={x^{s+\alpha -1}(1-x)^{f+\beta -1} \over \mathrm {B} (s+\alpha ,f+\beta )},\\\end{aligned}}}$$

\(P(p;α,β)\)에서 \(α\)가 number of heads, \(β\)가 nubmer of tails다.

이제 \(α,β\)에 대충 아무거나 넣고 그래프를 그려보면, prior(=P(head)의 dist)가 나온다.

시행횟수 (\(N=α+β\))가 많아질수록,(head가 N/2에 근접할 때) 가운데(=1/2)가 뾰족해지는 경향이 있다. 상식적인 결과.

4.3. Posterior Belief Distribution

위 퍼온 식에서 마지막 식(\(P(x | s, f) \))이 posterior belief.

Prior belief가 \(P(\theta | \alpha, \beta) \)일 때, posterior belief는 \(P(\theta | z + \alpha , N - z + \beta)\)가 된다.

mean과 variance만 알면 \(\alpha, \beta\)를 알 수 있으므로[1][2], 사건의 관찰로부터 our belief about the model parameter(\(θ\))를 추정할 수 있다.

5. Test for Significance – Frequentist vs Bayesian

5.1. p-value

taking an example of p-value as 0.02 for a distribution of mean 100
=There is 2% probability that the sample will have mean equal to 100.

즉, \(H_0\)(=no difference)가 참일 확률.
보다 일반적으로는, ‘실험결과가 우연히 발생할 확률’(what the odds are that your results could have happened by chance [3]).

따라서 일반적인 공식은 없으며 상황에 따라 정의해서 쓰면 된다. 보통 모집단은 정규분포를 가정하므로, 관찰 집단의 스코어(예를 들어 t-score[1], 혹은 z-score)를 구한 후 정규분포표에서 면적을 본다. 모표준편차를 모르는 경우가 대다수 이므로, t-score로 p-value를 구할 때 sample size에 영향받게 되는데, 이것이 p-value의 단점이다.

5.2. Confidence Intervals

p-value와 같은 defect를 가짐.

5.3. Bayes Factor

Baysian framework에서 p-value와 같은 역할을 함.

The null hypothesis in bayesian framework : \(P(θ)=\infty\) at fixed \(θ\), and \(P(θ)=0\) elsewhere.

Bayes factor is defined as the ratio of the posterior odds to the prior odds,

$$\begin{equation} \Large \text{ BF}= \frac{\text{Posterior odds}}{\text{Prior odds}} = \frac{\frac{ P(M=null | z, N)}{P(M=alt | z, N)}}{ \frac{P(M=null)}{P(M=alt)}} \end{equation}$$

To reject a null hypothesis, a BF <1/10 is preferred.

훌륭한 한글 자료가 있다. (아래 인용은 모두 그 자료에서 인용해온 것이다) 이에 따라 다시 쓰면, $$ \large \text{(Posterior odds)} = \text{(Bayes Factor)} \times \text{(Prior odds)} $$ $$ \begin{equation} \large \frac{P(H_1|D)}{P(H_0|D)} = \frac{P(D|H_1)}{P(D|H_0)} \times \frac{P(H_1)}{P(H_0)} \end{equation} $$

위 공식의 의미는 BF는 데이터를 관측한 뒤의 Odds ratio가 데이터 관측 전의 Odds ratio의 몇 배인지를 나타낸다는 것이다. 다시 말해 데이터 관측 후에 각각의 가설이 참이라는 것에 대한 믿음의 비율이 몇 배나 증가(감소)했는지를 나타낸다. BF의 값이 1보다 크면 대안가설이, 1보다 작으면 영가설이 데이터에 의해 더 많은 지지를 받는다고 생각할 수 있으며, BF의 값이 1에서 멀어질수록 사후믿음이 많이 변화했다고 생각할 수 있다.

위 (1)식과 (2)식이 결과값은 같으나 일반적으로 (2)의 표현을 쓰는듯 하다.[4] (1)은 분모분자의 순서가 의미상 뒤바뀐것이 아니고, null hypothesis를 어떻게 잡느냐에 따라 다른것이다.

BF는 각각의 가설이 데이터를 설명하는 정도의 비율이라 이해할 수 있다. 물론 여기서 두 가설은 굳이 영가설/대안가설일 필요는 없다.

위키에도 단순히 M1, M2라고 되어있다.(D:observed data, M:model)

H1이나 H0는 (당연하게도) 이미 아는 것이므로, 관찰(D)만 하고 나면 Bayes Factor(\(=\frac{P(D|H_1)}{P(D|H_0)}\))계산은 어렵지 않다.[5][6]

5.4. High Density Interval (HDI)

Since HDI is a probability, the 95% HDI gives the 95% most credible values. It is also guaranteed that 95 % values will lie in this interval unlike C.I.

confidence interval (frequentist의 관점에서. baysian은 credible interval이라고 하는것 같다) 그래프에서 가장 밀도가 높은 부분.

관련해서 위에 인용한 블로그의 또다른 포스트에 좋은 부분이 있다.

95% 신뢰구간은 그것을 계속 만들었을 때, 모든 신뢰구간들 중 95%가 모수치를 포함하도록 설계한 것이다. 그런데 이 때 개별 신뢰구간이 모수치를 포함할 확률이 95%라고 말해서는 안 된다. 왜냐하면 여기서 '95%' 라는 확률은 빈도주의적 의미를 가지며, 따라서 개별 구간에 대해서는 적용할 수 없기 때문이다. 개별 신뢰구간이 모수치를 포함할 확률은 그냥 0 또는 1, 다시 말해 포함하거나 포함하지 않거나 둘 중 하나다. 그러나 95% 신용구간은 그 구간이 모수치를 포함한다는 사건에 대한 믿음이 0.95임을 나타내는 것이다. 그리고 이 믿음은 개별 신용구간에 대해 적용할 수 있다. 따라서 개별 신용구간이 모수치를 포함할 확률이 95%라고 말할 수 있다.


  1. 모집단의 편차를 모를 때, 샘플의 개수가 15개 미만일때 주로 쓴다 함. 식은 \( t = \frac{\bar{x} - \mu_0}{ s / \sqrt{n}} \) where \(\mu_0\) is population mean, \(s\) is sample standard deviation.


blog comments powered by Disqus