###################################################################################################### # # Gamerman and Lopes (2006) # Example 5.1 (pages 143-5) – Figures 5.1 (page 144) and 5.2 (page 146) # ###################################################################################################### # # Poisson data with change point and conditionally conjugate Gamma priors: # # Model: yi |lambda,m ~ Poi(lambda) i=1,...,m # yi |phi,m ~ Poi(phi) i=m+1,...,n # # Prior: m ~ U{1,...,n} # lambda ~ Gamma(alpha,beta) # phi ~ Gamma(gamma,delta) # # # Figure 5.1 shows typical trajectoriesof the Gibbs sampler for the pair (phi,lambda) # # Figure 5.2 shows the data and its apparent change point plus posterior summaries # from the Gibbs output # # Dataset: 4 5 4 1 0 4 3 4 0 6 3 3 4 0 2 6 3 3 5 4 5 3 1 4 4 1 5 5 3 # 4 2 5 2 2 3 4 2 1 3 2 2 1 1 1 1 3 0 0 1 0 1 1 0 0 3 1 0 3 # 2 2 0 1 1 1 0 1 0 1 0 0 0 2 1 0 0 0 1 1 0 2 3 3 1 1 2 1 1 # 1 1 2 4 2 0 0 0 1 4 0 0 0 1 0 0 0 0 0 1 0 0 1 0 1 # # Additional References: # # * Carlin, Gelfand and Smith (1992) # * Tanner (1996, page 147) # ###################################################################################################### rm(list=ls()) quant025=function(x){quantile(x,0.025)} quant975=function(x){quantile(x,0.975)} # full conditional of m full = function(m,lambda,phi,y,n,alpha,beta,gamma,delta){ lambda^(alpha-1+ifelse(m>1,sum(y[1:m]),0))*exp(-(beta+m)*lambda)*phi^(gamma-1+ifelse(m1,sum(y[1:m]),0)+alpha,m+beta) phi = rgamma(1,ifelse(m