블로그 보관함

레이블이 bayesian인 게시물을 표시합니다. 모든 게시물 표시
레이블이 bayesian인 게시물을 표시합니다. 모든 게시물 표시

2012년 10월 20일 토요일

조건부 확률의 조건부 확률. posterior predictive distribution.

조건부 확률

조건부 확률을 보통 $A$, $B$ 기호를 가지고 이야기하지만 여기서는 좀 헤깔릴 수가 있으니 $Y$, $A$로 표시해 보자. $Y$는 관심 사건이고 $A$는 주어진 조건에 해당하는 사건이다. 조건부 확률의 기본적인 정의에 따라 쓰면 다음과 같다.

\[
P(Y|A) = \frac{P(Y, A)}{P(A)}
\]


그리고 전확률 법칙(Law of Total Probability)라는 것도 있다. 표본 공간이 $B_1,B_2,\cdots,B_n$으로 분할(partition)되어있을 때
\[
P(Y) = \sum_{i=1}^n P(Y|B_i)P(B_i)
\]
이 성립한다는 법칙이다. 이것은 $P(Y)$를 구하기가 힘들 때 $P(Y|B_i)$들은 구하기 쉽고 각 $P(B_i)$들을 이미 알고 있는 경우에 유용하게 쓸 수 있는 법칙이다.

그런데, 이런 경우를 생각해보자. $P(Y|A)$를 구해야하는데 이것을 구하기가 힘들다. 그런데, $B_i$로 이 문제를 분할하여 구하는 것은 쉽다고 하자. 조건부 확률의 조건부 확률을 생각해보는 것이다. 다음처럼 구할 수 있다.
\[
P(Y|A) = \sum_{i=1}^n P(Y|B_i,A)P(B_i|A)
\]
이 식을 바로 생각하려고 하면 헤깔릴 때가 있다. $Y$를 $A$라는 조건 아래서 생각하고 있는 데 거기에 $B_i$라는 조건을 추가로 고려하면 어떻게 될까, 하는 것인데. 두번째 항을 $P(A|B_i)$인 것으로 착각을 할때가 있다. 식을 따져보면 당연한 것이기는 하다.
\[
\sum_{i=1}^n P(Y|B_i,A)P(B_i|A)
= \sum_{i=1}^n \frac{P(Y,B_i,A)}{P(B_i,A)}\frac{P(B_i,A)}{P(A)}
= \sum_{i=1}^n \frac{P(Y,B_i,A)}{P(A)}
= \frac{P(Y,A)}{P(A)}
= P(Y|A)
\]

Posterior Predictive Distribution


미지의 평균과 분산이 $\theta =(\mu, \sigma^2)$인 대상에 대해 $y=(y_1,\cdots,y_n)$을 관측했다. $\tilde y$는 다음 번 관측 대상의 값이다. 이때 $\tilde y$의 분포를 posterior predictive distribution이라고 한다. 다음처럼 구한다.

\begin{align}
p(\tilde y|y) &= \int p(\tilde y, \theta | y) d\theta\\
&= \int p(\tilde y|\theta, y)p(\theta|y) d\theta\\
&= \int p(\tilde y|\theta)p(\theta | y) d\theta.\\
\end{align}
마지막 행이 성립하는 것은 $\tilde y$와 $y$가 given $\theta$에서 조건부 독립이기 때문이다.

예제


여자아이가 태어날 확률을 $\theta$라고 하자. 서로 독립적인 $n$명의 신생아를 관찰하였을 때 여자아이의 수는 이항분포 $Binomial(n, \theta)$를 따른다. 사전분포로는 균일분포 $\theta \sim Unif(0,1)$을 사용하자. 1000명의 신생아를 관찰하였더니 485명이 여자아이였다. 1001번째 신생아가 여자아이일 확률은?

$n$명 중 여자아이의 수 $y$라고 하자. likelihood는
\[
p(y|\theta) = \binom{n}{y} \theta^y(1-\theta)^{n-y}
\]
piror distribution는
\[
\pi(\theta) = 1, \qquad 0 < \theta < 1
\]
posterior distribution은
\begin{align}
p(\theta|y) &\propto p(y|\theta)\pi(\theta)\\
&\propto \theta^y (1-\theta)^{n-y}
\end{align}
형태이므로 $Beta(y+1, n-y +1)$ 분포임을 알 수 있다.

이제 새로 태어날 아이에 대한 관측을 $\tilde y$라고 하면 여자아이일 확률은
\begin{align}
p(\tilde y = 1| y) &= \int_0^1 p(\tilde y = 1 | \theta,y)p(\theta|y) d\theta\\
&= \int_0^1 p(\tilde y = 1 | \theta)p(\theta|y) d\theta \\
&= \int_0^1 \theta p(\theta|y) d\theta\\
&= E(\theta|y) & (\theta|y \sim Beta(y+1, n-y+1))\\
&= \frac{y+1}{n+2} & (\because X\sim Beta(\alpha, \beta),\; EX = \alpha/(\alpha+ \beta))\\
\end{align}

따라서, 새로 태어날 아이가 여자아이일 확률을 486/1002.





2012년 2월 7일 화요일

베이즈통계 책



  • Berger, J. O. (1985). Statistical Decision Theory and Bayesian Analysis. Springer- Verlag. 
  • Ghosh, J.K. and Ramamoorthi (2002). Bayesian Nonparametrics. Springer. 
  • Lange, K. (1998). Numerical Analysis for Statisticians. Springer. 
  • Robert, C. P. and Casella, G. (1999), Monte Carlo Statistical Methods. Springer. 
  • Norris, J.R. (1997). Markov Chains. Cambridge. 
  • Chen. M.-H., Shao, Q.-M. and Ibrahim, J.G. (2000). Monte Carlo Methods in Bayesian Computation. Springer.  
  • Gelman, A., Carlin, J.B., Stern, H.S. and Rubin, D.B. (2003). Bayesian Data Analysis. Chapman & Hall/CRC. 
  • Ghosh, J.K., Delampady, M. and Samanta, T. (2006). An Introduction to Bayesian Analysis. Springer. 
  • Congdon, P. (2003). Applied Bayesian Modelling. Wiley. 
  • Congdon, P. (2005). Bayesian Models for Categorical Data. Wiley. 
  • Nyhoff, L. R. and Leestma, S. C. (1996). Introduction to Fortran 90 for Engineers and Scientists. Prentince Hall.

2012년 1월 14일 토요일

베이지안에서 많이 사용하는 분포



Univariatepdf Multivariate pdf
Binomial$(n,p)$ $\binom{n}{x}p^x(1-p)^{n-x}$ Multinomial$(n,p_1,\cdots,p_k)$ $\frac{n!}{x_1!\cdots x_k!}p_1^{x_1}\cdots p_k^{x_k}$, $\sum x_i = n$
Normal$(\mu,\sigma^2)$ $(2\pi\sigma^2)^{-1/2}\exp\left\{-\frac{(x-\mu)^2}{2\sigma^2}\right\}$ Multivariate Normal$(\mu, \Sigma)$ $(2\pi)^{-\frac{k}{2}}|\Sigma|^{-\frac{1}{2}}\exp\left\{(x-\mu)'\Sigma^{-1}(x-\mu)\right\}$
Gamma$(\alpha,\beta)$ $\frac{x^{\alpha-1}e^{-x/\beta}}{\Gamma(\alpha)\beta^\alpha}$ Wishart$(n,\Sigma)$
Beta$(\alpha, \beta)$ $\frac{x^{\alpha-1}(1-x)^{\beta-1}}{\text{B}(\alpha,\beta)}$ Dirichlet$(\alpha_1,\cdots,\alpha_{k+1})$

  • Exponential$(\beta)$: Gamma$(\alpha=1, \beta)$
  • Chi-squared$(k)$: Gamma$(\alpha=k/2, \beta=1/2)$
  • Uniform$(0,1)$: Beta$(\alpha=1, \beta=1)$



역감마분포 Inverse-gamma distribution


$1/X$가 Gamma 분포를 따르면 $X$는 Inverse-gamma 분포를 따른다고 한다.
\[
f(x) = \frac{\beta^\alpha)}{\Gamma(\alpha)} x^{-(\alpha+1)} e^{-\beta/x}
\]


디리클레 분포 Dirichlet distribution

디리클레 분포의 pdf:
\[
f(x_1,\cdots,x_{k};\alpha_1,\cdots,\alpha_{k+1}) = \frac{\Gamma(\sum_{i=1}^{k+1}\alpha_i)}{\prod_{i=1}^{k+1}\Gamma(\alpha_i)}\prod_{i=1}^{k+1} x_i^{\alpha_i -1 }
\]

위샤트 분포 Wishart distribution

다변량정규분포를 따르는 $n$개의 iid 확률벡터 $X_1,\cdots,X_n \stackrel{iid}{\sim} N(0,\Sigma)$가 있을 때
\[
\sum_{i=1}^n X_iX_i^T \sim \text{Wishart}(n,\Sigma)
\]
이다.

역위샤트 분포 Inverse-Wishart distribution