Skip to Main Content
Table 5

S-Plus program

function (bhat, vhat, z, niter) 
### Define the number of estimates (n) and the number of parameters in the prior model (p) 
n <− length (bhat) 
p <− ncol (z) 
### Set initial value for Vhattrue (vart) to 0 
vart <− 0 
### Generate vector to store values of Vhattrue from each iteration 
v <− vector (length = niter+ 1) 
v [1] <− 0 
### Generate column of 1s for use in calculations 
I <− matrix (1, n, 1) 
### Start iterative loop 
for (i in 1:niter) { 
### Define weights (W) and calculate their sum (w) 
W <− solve (vhat+ vart* diag(n)) 
w <− t(I) %*% W %*% I 
### Calculate lnSIRmean (pi) and a vector of prior means (mu) 
pi <− solve (t(z) %*% W %*% z) %*% t(z) %*% W %*% bhat 
mu <− z %*% pi 
### Calculate D, Vhatobs (varo) and Vhatmean (varm) 
D <− bhat− mu 
varo <− t(D) %*% W %*% D/w 
varm <− (t(I) %*% W %*% vhat %*% I)/w 
function (bhat, vhat, z, niter) 
### Define the number of estimates (n) and the number of parameters in the prior model (p) 
n <− length (bhat) 
p <− ncol (z) 
### Set initial value for Vhattrue (vart) to 0 
vart <− 0 
### Generate vector to store values of Vhattrue from each iteration 
v <− vector (length = niter+ 1) 
v [1] <− 0 
### Generate column of 1s for use in calculations 
I <− matrix (1, n, 1) 
### Start iterative loop 
for (i in 1:niter) { 
### Define weights (W) and calculate their sum (w) 
W <− solve (vhat+ vart* diag(n)) 
w <− t(I) %*% W %*% I 
### Calculate lnSIRmean (pi) and a vector of prior means (mu) 
pi <− solve (t(z) %*% W %*% z) %*% t(z) %*% W %*% bhat 
mu <− z %*% pi 
### Calculate D, Vhatobs (varo) and Vhatmean (varm) 
D <− bhat− mu 
varo <− t(D) %*% W %*% D/w 
varm <− (t(I) %*% W %*% vhat %*% I)/w 
Close Modal

or Create an Account

Close Modal
Close Modal