Suponga que tenemos una muestra aleatoria X1,...,X10 tal que Xj∼Poisson(θ). Recordemos que
set.seed(10000)
n<-10
X<-rpois(n, 4) #suponemos que theta = 4.
X
## [1] 4 4 3 4 3 3 5 5 4 1
mean(X)
## [1] 3.6
Tenemos que la verosimilitud es:
L(θ|x)=θ∑nj=1xje−nθ∏nj=1xj!
θ∼Unif(0,B) donde B va a representar un valor arbitrario muy grande.
La distribución a posteriori es:
π(θ|x)∝L(θ|x)π(θ)
⇒π(θ|x)∝θ∑xje−nθ∏xj!⋅1B∝θnˉxe−nθ Esto indica que la distribución posterior tiene nucleo de una distribución gamma:
θ|x∼Gamma(nˉx+1,n)
B<-100
alfa1<- n*mean(X)+1
beta1<- n
theta <- seq(0,10,by=0.1)
pi.theta <- dgamma(x=theta,shape=alfa1,rate=beta1)
plot(theta,pi.theta,type="l")
abline(v=mean(X),col=2)
abline(h=1/B,col=3)
La media posterior usando una previa no informativa.
alfa1/beta1
## [1] 3.7
Suponga que conocemos de antemano información respecto a θ,
π(θ)=βαθα−1e−βθΓ(α) π(θ|x)=L(θ|x)π(θ)∫+∞0L(θ|x)π(θ)∝L(θ|x)π(θ)=θnˉxe−nθ∏xj!⋅βαθα−1e−βθΓ(α) ∝θnˉxe−nθ⋅θα−1e−βθ=θnˉx+α−1e−θ(n+β)
Por lo tanto concluimos que θ|x∼Gamma(nˉx+α,n+β).
alfa0 <- 4
beta0 <- 2
alfa1<- n*mean(X)+alfa0
beta1<- n+beta0
theta <- seq(0,10,by=0.1)
pi.theta.prior <- dgamma(x=theta,shape=alfa0,rate=beta0)
pi.theta <- dgamma(x=theta,shape=alfa1,rate=beta1)
plot(theta,pi.theta.prior,type="l", ylim=c(0,1))
points(theta,pi.theta,type="l",col=2)
abline(v=mean(X),col=3)
La media posterior usando una previa informativa (depende de la información a priori).
alfa1/beta1
## [1] 3.333333
Recuerde que:
E(θ|x)=nˉx+β(αβ)n+β