授業で使います.
Gelman et al.: Bayesian Data Analysis, p.52, 2nd Edition.
ポアソン分布とガンマ分布の関係については繁桝算男『ベイズ統計入門』64ページを参照.
#mimetex(p(y|\theta) = \frac{\theta^y \, e^{-\theta}}{y!})
#mimetex(\bf{y} = y_i, \dots , y_n)
#mimetex(p(\bf{y}|\theta) = l(\theta|\bf{y}) = \Pi \frac{1}{y_i!} \theta^{y_i} \, e^{-\theta})
#mimetex( \propto \theta^{t(y)} \, e^{-n \theta}) 指数属で表現すると
#mimetex( \propto e^{-n\theta}\, e^{t(y) log \theta} ) 文系学生相手にするので,指数法則を指摘する.
#mimetex(\theta^y = e^{log(\theta^y)} = e^{y log \theta}) 指数属とは関数が次の形で表されること(Lee: Bayesian Statistics, pp.60).
#mimetex(p(\bf{x}| \theta) = g(\bf{x}) \, h(\theta) \, e^{t(\bf{x}) \, \phi(\theta)}) 上の式では&mimetex(\frac{1}{y!});が消えているので注意
#mimetex(p(\theta) \propto (e^{-\theta})^n e^{v log \theta} )
#mimetex(\theta|\bf{y} \sim Gamma(\alpha + n \bar{y}, \beta + n))
#mimetex(y_i \sim Poisson(x_i \theta)) &mimetex(y_i); と &mimetex(x_i); が観測数で,&mimetex(\theta); が未知のパラメータだが,&mimetex(x); を exposure,&mimetex(\theta); をrate と表現しており,分野違いの人間はいつまでたっても馴染みにくい.
#mimetex(y \sim Poisson(e \lambda))
#mimetex(\theta^{16-1} \, e^{-15174\, \theta} = Gamma(16,15174 ))
my.alpha <- 16 my.beta <- 15174 lam <- my.alpha/my.beta lambdaA <- rgamma(1000, shape = my.alpha + 1, rate = my.beta + 66) lambdaB <- rgamma(1000, shape = my.alpha + 1767, rate = my.beta + 4) lambda <- seq(0, max(c(lambdaA, lambdaB)), length = 500)
par(mfrow = c(2,1))# , mar = rep(1, 4)) hist(lambdaA, freq = FALSE, main = "", ylim =c(0, 1600)) lines(lambda, dgamma(lambda, shape = my.alpha, my.beta), col = "blue", lwd = 3) lines(lambda, dgamma(lambda, shape = my.alpha+ 1, my.beta + 66), col = "red", lwd = 3) legend(0.0015, 1500, legend= c("prior", "posterior"), col = c("blue","red"), lwd = 3) hist(lambdaB, freq = FALSE, main = "", ylim =c(0, 1600)) lines(lambda, dgamma(lambda, shape = my.alpha, my.beta), col = "blue", lwd = 3) lines(lambda, dgamma(lambda, shape = my.alpha+ 4, my.beta + 1767), col = "red", lwd = 3) legend(0.0015, 1500, legend= c("prior", "posterior"), col = c("blue","red"), lwd = 3)
#mimetex(f(y) = \frac{f(y|\lambda) \, g(\lambda)}{g(y|\lambda)}) こういうページも参考に.