# Program 21 # For fixed beta vectors and their prior probabilities, this program uses experimental results to # calculate the posterior probabilities for those vectors. # It is necessary to specify (i) the matrix whose columns are the potential parameter vectors, # (ii) the prior probabilities of these vectors< (iii) values of common parameters, and (iv) the # results of the experiment f <- function(xvec) { f <- c(1,xvec) f } #prior properties of parameters betamat <- matrix(c(-0.2,-0.2,0.2,0.2,0.8,1.2,0.8,1.2,0.8,1.2,1.2,0.8),4,3) psivec <- c(0.1,0.2,0.3,0.4) h <- (dim(betamat))[1] s <- 4 m <- 2 p <- 3 #properties of design and the experiment xmat <- matrix(c(-1,-1,0.9689,1,-1,1,1,-1),s,m) nvec <- c(7,9,5,9) yvec <- c(2,2,4,4) probmat <- matrix(0,s,h) posterior <- rep(0,h) for (ell in 1:h) { betavec <- betamat[ell,] for (em in 1:s) { xvec <- f(xmat[em,]) eta <- sum(betavec*xvec) probmat[em,ell] = 1/(1+exp(-eta)) } } probmat condprob <- rep(0,h) for(i in 1:h) {condprob[i] <- prod(dbinom(yvec,nvec,probmat[,i])) } condprob temp <- condprob*psivec posterior <- temp/sum(temp) posterior