
####################################################
#    Function definitions for Chapter 14


####################################################
# A Gibbs sampler
gibbsNormal <- function(n,burnIn,rho){
  # precompute invariant quantity
  r2 <- sqrt(1 - rho^2)
  x1 <- 0; x2 <- 0
  # run burn-in
  for (i in 1:burnIn){
    x1 <- rnorm(1,rho*x2,r2)
    x2 <- rnorm(1,rho*x1,r2)}
  mat <- matrix(nrow=n,ncol=2)
  for (i in 1:n) {
    x1 <- rnorm(1,rho*x2,r2)
    x2 <- rnorm(1,rho*x1,r2)
    mat[i,] <- c(x1,x2)}
  return(mat)
}

