# Beginners – Representations of past and back distributions for a model

I have an exercise that requires the representation of the previous and the back distribution in the Poisson gamma model. I have inspired it (I think it is right)
In answer to this question https://stats.stackexchange.com/questions/70661/wohin-the-beta-prior-affect-the-posterior-unter-a-binomial-likelihood

Is there something that can improve the code?

``````Colors = c (red, blue, green, orange, purple)

n = 10

Lambda = 0.2

x = rpois (n, lambda)
Raster = seq (0,2, 0,01)

alpha = c (.5,5,1,2,2)
beta = c (.5,1,3,2,5)

Order (raster, raster, type = "n", xlim = c (0,1), ylim = c (0,4), xlab = "", ylab = "Prior Density"),
main = "pre-distributions", las = 1)
for (i in 1: length (alpha)) {
before = dgamma (raster, alpha[i]1 / beta[i])
Lines (grid, in front, Col = colors[i]lwd = 2)
}

Legend ("top left", legend = c ("gamma (0,5,0,5)"), "gamma (5,1)", "gamma (1,3)", "gamma (2,2) "," Gamma "(2 5)"),
lwd = rep (2,5), col = colors, bty = "n", ncol = 3)

for (i in 1: length (alpha)) {
dev.new ()
Order (raster, raster, type = "n", xlim = c (0,1), ylim = c (0,10), xlab = "", ylab = "Density", xaxs = "i", yaxs = " I",
main = "before and after distribution")

alpha.star = alpha[i] + sum (x)
beta.star = beta[i] + n
before = dgamma (raster, alpha[i],Beta[i])
post = dgamma (raster, alpha.star, beta.star)

Lines (raster, post, Lwd = 2)
Lines (grid, in front, Col = colors[i]lwd = 2)
Legend ("topright", c ("Prior", "Posterior")), col = c (Colors[i]"black"), lwd = 2)

}
``````