# # # data ex1_2.greece<-data.frame( game=1:6 ) ex1_2.greece$opponent<- c("Portugal", "Spain" , "Russia", "France", "Chech Rep.", "Portugal" ) ex1_2.greece$scored <-c(2, 1, 1, 1, 0, 1) ex1_2.greece$conceded<-c(1, 1, 2, 0, 0, 0) ex1_2.greece$total <- ex1_2.greece$scored + ex1_2.greece$conceded step<-0.01 a<-0.001 b<-0.001 x<-seq(step, 3, step) y <-dgamma( x, sum(ex1_2.greece[,3])+a, 6+b ) y2<-dgamma( x, sum(ex1_2.greece[,4])+a, 6+b ) postscript('chap1_ex01_plot1.ps', width = 10.0, height = 6.0, horizontal=FALSE) par( xaxs='i', yaxs='i', bty='l' , cex=1.3) plot(x,y,type='l', ylab='Posterior density', xlab='Expected Number of Goals', ylim=c(min(c(y,y2)), max(c(y,y2,1.5))+0.1 ) ) lines(x,y2, col=2, lty=2) text( 0.85,1.39,'Goals Conceded', col=2) text( 1.2,1.07, 'Goals Scored' ) graphics.off() #------------------ # plot with prior ex1_2.greece$total <- ex1_2.greece$scored + ex1_2.greece$conceded step<-0.01 a1<-1 b1<-1 a2<-1 b2<-2 x<-seq(step, 3, step) y <-dgamma( x, sum(ex1_2.greece[,3])+a1, 6+b1 ) y2<-dgamma( x, sum(ex1_2.greece[,4])+a2, 6+b2 ) postscript('chap1_ex01_plot2.ps', width = 10.0, height = 6.0, horizontal=FALSE) par( xaxs='i', yaxs='i', bty='l' , cex=1.3) plot(x,y,type='l', ylab='Posterior density', xlab='Expected Number of Goals', ylim=c(min(c(y,y2)), max(c(y,y2))+0.1 ) ) lines(x,y2, col=2, lty=2) text( 0.95,1.530,'Goals Conceded', col=2) text( 1.3,1.10, 'Goals Scored' ) graphics.off()