Prior for proportion
The prior for proportion should be chosen within Beta distribution.
Beta distribution in Wikipedia
Beta distribution has two parameters, alpha and beta (alpha>0 and beta>0) and it used a parameter 0≤x≤1. x can be a proportion. For such a reason, Beta distribution is perfect to be used as a prior for proportion.
Look at the shape of beta:
colors = c("red","blue","green","orange","purple", "black")
grid = seq(0,1,.01)
alpha = c(.5,5,1,2,2, 1)
beta = c(.5,1,3,2,5, 1)
plot(grid,grid,type="n",xlim=c(0,1),ylim=c(0,4),xlab="",ylab="Prior Density",
main="Prior Distributions", las=1)
for(i in 1:length(alpha)){
prior = dbeta(grid,alpha[i],beta[i])
lines(grid,prior,col=colors[i],lwd=2)
}
legend("topleft", legend=c("Beta(0.5,0.5)", "Beta(5,1)", "Beta(1,3)", "Beta(2,2)", "Beta(2,5)", "Beta(1,1)"),
lwd=rep(2,6), col=colors, bty="n", ncol=2, cex=0.8)
Now let see the influence of the prior on the posterior:
n = 10
N = 10
prob = .2
x = rbinom(n,N,prob)
for(i in 1:length(alpha)){
# dev.new()
plot(grid,grid,type="n",xlim=c(0,1),ylim=c(0,10),
xlab="",ylab="Density",xaxs="i",yaxs="i",
main="Prior and Posterior Distribution")
alpha.star = alpha[i] + sum(x)
beta.star = beta[i] + n*N - sum(x)
prior = dbeta(grid,alpha[i],beta[i])
post = dbeta(grid,alpha.star,beta.star)
lines(grid,post,lwd=2)
lines(grid,prior,col=colors[i],lwd=2)
legend("topright",c("Prior","Posterior"),col=c(colors[i],"black"),lwd=2)
}
Beta distribution in Wikipedia
Beta distribution has two parameters, alpha and beta (alpha>0 and beta>0) and it used a parameter 0≤x≤1. x can be a proportion. For such a reason, Beta distribution is perfect to be used as a prior for proportion.
Look at the shape of beta:
colors = c("red","blue","green","orange","purple", "black")
grid = seq(0,1,.01)
alpha = c(.5,5,1,2,2, 1)
beta = c(.5,1,3,2,5, 1)
plot(grid,grid,type="n",xlim=c(0,1),ylim=c(0,4),xlab="",ylab="Prior Density",
main="Prior Distributions", las=1)
for(i in 1:length(alpha)){
prior = dbeta(grid,alpha[i],beta[i])
lines(grid,prior,col=colors[i],lwd=2)
}
legend("topleft", legend=c("Beta(0.5,0.5)", "Beta(5,1)", "Beta(1,3)", "Beta(2,2)", "Beta(2,5)", "Beta(1,1)"),
lwd=rep(2,6), col=colors, bty="n", ncol=2, cex=0.8)
Now let see the influence of the prior on the posterior:
n = 10
N = 10
prob = .2
x = rbinom(n,N,prob)
for(i in 1:length(alpha)){
# dev.new()
plot(grid,grid,type="n",xlim=c(0,1),ylim=c(0,10),
xlab="",ylab="Density",xaxs="i",yaxs="i",
main="Prior and Posterior Distribution")
alpha.star = alpha[i] + sum(x)
beta.star = beta[i] + n*N - sum(x)
prior = dbeta(grid,alpha[i],beta[i])
post = dbeta(grid,alpha.star,beta.star)
lines(grid,post,lwd=2)
lines(grid,prior,col=colors[i],lwd=2)
legend("topright",c("Prior","Posterior"),col=c(colors[i],"black"),lwd=2)
}
Commentaires
Enregistrer un commentaire