nc.sub.df <- read.table("http://jeffgill.org/files/jeffgill/files/nc.sub_.dat_.txt", header=TRUE) library(bayesm); library(BaM) # FOR THE rwishart AND rmultinorm FUNCTION Alpha <- 3 + nrow(nc.sub.df) Beta.inv <- solve(diag(3)*100) m <- c(250,16,88) n0 <- 0.01 x.bar <- apply(nc.sub.df,2,mean) S.sq <- var(nc.sub.df) k <- (n0 * nrow(nc.sub.df))/(n0 + nrow(nc.sub.df)) p.Beta <- solve( Beta.inv + S.sq + k * round((x.bar-m) %*% t(x.bar-m),2) ) Sigma <- array(NA,dim=c(3,3,1)) for (i in 1:10000) Sigma <- array(c(Sigma,rwishart(Alpha,p.Beta)$IW),dim=c(3,3,(i+1))) Sigma <- Sigma[,,-1] Sigma.Mean <- apply(Sigma,c(1,2),mean) # ANALYTICAL MEAN OF THE INVERSE WISHART: ( (Alpha-ncol(nc.sub.df)-1)^(-1) )*solve(p.Beta) # SIGMA Sigma.SD <- apply(Sigma,c(1,2),sd) # VECTOR MEAN BY SIMULATION Mu <- rmultinorm(5000,(n0*m + nrow(nc.sub.df)*x.bar)/(n0 + nrow(nc.sub.df)), Sigma.Mean/(n0+nrow(nc.sub.df))) apply(Mu,2,quantile, probs = c(0.01,0.25,0.50,0.75,0.99))