############################################################################################################## # # Example 2.1 (pages 44, 48 and 50) and Example 2.3 (pages 48-49) – Figure 2.1 (page 49) # # Normal data with unknown mean and known variance. # # Example 2.1 – Normal prior for the unknown mean # Example 2.3 – Cauchy prior for the unknown mean # ############################################################################################################## # # Author : Hedibert Freitas Lopes # Graduate School of Business # University of Chicago # 5807 South Woodlawn Avenue # Chicago, Illinois, 60637 # Email : hlopes@ChicagoGSB.edu # ############################################################################################################### # Sufficient statistics xbar = 7.0 sig2n = 4.5 # Hyperparameters of the normal prior mu0 = 0.0 tau20 = 1.0 # Hyperparameters of the conjugate normal posterior tau21 = 1/(1/sig2n+1/tau20) mu1 = tau21*(xbar/sig2n+mu0/tau20) # Figure 2.1 # ---------- x = seq(-4,14,length=5000) f.normal = dnorm(x,mu1,sqrt(tau21)) f.normal = f.normal/max(f.normal)*0.0045 f.cauchy = dnorm(x,xbar,sqrt(sig2n))/(tau20+(x-mu0)^2) f.cauchy = f.cauchy/max(f.cauchy)*0.0015 par(mfrow=c(1,1)) plot(x,f.normal,xlab="",ylab="",main="",type="l",axes=F) axis(1,at=c(-4,0,5,10,14)) axis(2) lines(x,f.cauchy,lty=2)