Académique Documents
Professionnel Documents
Culture Documents
parameter(alpha,beta,phi).
> par(mfrow=c(1,3),oma=c(0,0,2,0))
> plot(alpha,palpha,type="l",main="alpha",col="red")
> plot(beta,pbeta,type="l",main="beta",col="red")
> plot(phi,pphi,type="l",main="phi",col="red")
> mtext("Priors",line=0.5,outer=T)
We define the number of simulations and the burn-in period. A number of 200000 simulations from the
equilibrium distribution will be considered, but the first 100000 will be ignored (dropped). So only the
last 100000 simulated values will be used for our inference.
#===Data===
Y<-c(1,3,3,3,5)
x<-c(1,2,3,4,5)
set.seed(1)
system.time(
for(h in 2:Reps){
})
> alpha.Gibbs[1:10]
[1] 0.000000 2.719784 3.200123 3.471718 2.628536 3.535587 3.179302
3.343338
[9] 3.442093 2.670470
> beta.Gibbs[1:10]
[1] 0.0000000 0.8580648 0.2742523 1.0601760 0.4227764 0.7848617
0.4397609
[8] 0.8231414 1.4743099 1.0035676
> phi.Gibbs[1:10]
[1] 1.0000000 0.8579634 0.4896854 0.9256390 0.8820678 1.1801804
1.0375200
[8] 0.2592386 0.4214273 2.5518368
> par(mfrow=c(4,1),oma=c(0,0,2,0))
>
> ts.plot(alpha.Gibbs,main="alpha")
> ts.plot(beta.Gibbs,main="beta")
> ts.plot(phi.Gibbs,main="phi")
>
> sigma.Gibbs <- 1/sqrt(phi.Gibbs)
> ts.plot(sigma.Gibbs,main="sigma")
>
> mtext("History plots", line = 0.5, outer=T)
Alpha si beta au convergenta, iar phi si sigma nu au convergenta.
par(mfrow=c(2,2),oma=c(0,0,2,0))
# alpha
y.density <- density(alpha.Gibbs[(Burn+1):Reps], width = 1)
y.max <- max(y.density$y)
plot(alpha,palpha,type="l",main="alpha",ylim=c(0,y.max),xlim=c(-
1,7),col="red",lwd=2)
lines(y.density,type="l",col="darkgreen")
legend(locator(1),c("Prior","Posterior"),text.col=c("red","darkgreen")
,bty="n",cex=.6)
# beta
y.density <- density(beta.Gibbs[(Burn+1):Reps], width = 1)
y.max <- max(y.density$y)
plot(beta,pbeta,type="l",main="beta",ylim=c(0,y.max),xlim=c(-
2,4),col="red",lwd=2)
lines(y.density,type="l",col="darkgreen")
legend(locator(1),c("Prior","Posterior"),text.col=c("red","darkgreen")
,bty="n",cex=.6)
# phi
y.density <- density(phi.Gibbs[(Burn+1):Reps], width = 1)
y.max <- max(y.density$y)
plot(phi,pphi,type="l",main="phi",ylim=c(0,y.max),xlim=c(0,20),col="re
d")
lines(y.density,type="l",col="darkgreen")
legend(locator(1),c("Prior","Posterior"),text.col=c("red","darkgreen")
,bty="n",cex=.6)
# sigma
y.density <- density(sigma.Gibbs[(Burn+1):Reps], width = 1)
y.max <- max(y.density$y)
summary(sigma.Gibbs[(Burn+1):Reps])
plot(y.density,type="l",
main="sigma",ylim=c(0,y.max),xlim=c(0,7),col="darkgreen",xlab="sigma")
legend(locator(1),c("Posterior"),text.col=c("darkgreen"),bty="n",cex=.
6)