## code to accompany the MVN (bivariate) example from ## lecture 11 of PSTAT 215A, Bayesian Inference, UCSB ## ## Robert B. Gramacy ## load necessary libraries library(mvtnorm) mu <- c(50,50) S2 <- rbind(c(64, 0), c(0,144)) S1 <- S2 + rbind(c(0, -48), c(-48, 0)) S3 <- S2 + rbind(c(0, 48), c(48, 0)) ## make the posterior image plot library(akima) N <- 200 y.grid <- seq(28, 72, length=N) g <- expand.grid(y.grid, y.grid) names(g) <- c("y1", "y2") ## negatively correlated p1 <- matrix(dmvnorm(g, mu, S1), nrow=N) image(y.grid, y.grid, p1) ## un-correlated p2 <- matrix(dmvnorm(g, mu, S2), nrow=N) image(y.grid, y.grid, p2) ## positively correlated p3 <- matrix(dmvnorm(g, mu, S3), nrow=N) image(y.grid, y.grid, p3)