## show plot code

```
################################################################################
library (bmmb)
# load and subset experimental data
data (exp_data, package = "bmmb")
= exp_data[exp_data$C_v=='m',]
men = men$height
mens_height
par(mfcol = c(3,3), mar =c(.1,.25,.1,.25), oma = c(4,3,3,1))
= seq (135, 210, 0.05)
x ####
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 3 ) )
likelihood = dnorm (x, 180, 100) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='Density',lwd=4,yaxs='i',
xlim = c(140, 210), ylim = c(0,1.1),xlab='',xaxt='n',cex.axis=1.3,yaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side=3,outer=FALSE,text="Observations = 3",line=1)
mtext (side=2,outer=FALSE,text=expression(paste("P(", mu,") = N(180,100)")),
line=1,cex=0.9)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 3 ) )
likelihood = dnorm (x, 180, 15) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(140, 210), ylim = c(0,1.1),xaxt='n',cex.axis=1.3,yaxt='n',
col=bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side=2,outer=FALSE,text=expression(paste("P(", mu,") = N(180,15)")),
line=1,cex=0.9)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 3 ) )
likelihood = dnorm (x, 180, 1) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(140, 210), ylim = c(0,1.1),cex.axis=1.3,yaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side=2,outer=FALSE,text=expression(paste("P(", mu,") = N(180,1)")),
line=1,cex=0.9)
####
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 10 ) )
likelihood = dnorm (x, 180, 100) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='Density',lwd=4,yaxs='i',
xlim = c(160, 185), ylim = c(0,1.1),xlab='',yaxt='n',xaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior) ,col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side=3,outer=FALSE,text="Observations = 10",line=1)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 10 ) )
likelihood = dnorm (x, 180, 15) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(160, 185), ylim = c(0,1.1),yaxt='n',xaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 10 ) )
likelihood = dnorm (x, 180, 1) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(160, 185), ylim = c(0,1.1),yaxt='n',cex.axis=1.3,
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
####
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 675 ) )
likelihood = dnorm (x, 180, 100) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='Density',lwd=4,yaxs='i',
xlim = c(170, 183), ylim = c(0,1.1),xlab='',yaxt='n',xaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side=3,outer=FALSE,text="Observations = 675",line=1)
legend (174.75,.9,legend=c(expression(paste("Prior ","P(",mu,")")),
expression(paste("Likelihood ","P(y|",mu,")")),
expression(paste("Posterior ","P(",mu,"|y)"))),
lwd=4,lty=c(1,1,4),
col=c(bmmb::cols[4],bmmb::cols[3],bmmb::cols[7]),bty = "n",cex=1.2)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 675 ) )
likelihood = dnorm (x, 180, 15) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(170, 183), ylim = c(0,1.1),yaxt='n',xaxt='n',
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
= dnorm (x, mean (mens_height), sd (mens_height) / sqrt ( 675 ) )
likelihood = dnorm (x, 180, 1) ; posterior = likelihood * prior
prior plot (x, likelihood / max(likelihood), type = 'l', ylab='',lwd=4,yaxs='i',
xlim = c(170, 183), ylim = c(0,1.1),yaxt='n',cex.axis=1.3,
col = bmmb::cols[3])
grid()
lines (x, prior / max(prior),col=bmmb::cols[4],lwd=4)
lines (x, posterior / max (posterior),col=bmmb::cols[7], lty=2,lwd=4)
mtext (side = 1, outer = TRUE, text = "Apparent height (cm)", line = 2.5)
```