When using WinBUGS/OpenBUGS/JAGS, it is often necessary to provide a
Wishart prior distribution for the precision matrix of a
p
-dimensional random vector. It is common to use a Wishart
distribution with p+1
degrees of freedom in this case. The
question is what scale matrix to use. The BUGS languages parameterize the
Wishart distribution such that if a precision matrix M
is given
the prior distribution M ~ dwish(S,p+1)
for a pxp
scale
matrix S
and p+1
degrees of freedom, the expected value
of M
is p+1
times the inverse of S
.
The current function determines a diagonal scale matrix S
such
that the implied prior distribution for the inverse of M
, the
variance/covariance matrix of the random vector, under the
distribution M ~ dwish(S,p+1)
in the BUGS parameterization, has
medians of the diagonal elements approximately equal to some target
variances specified by target
. It iteratively tries values of
S
via Monte Carlo simulation to select a value of S
with
the desired property.
The value of reltol
determines how close the match must be.
Larger values of nsim
and smaller values of reltol
will
lead to smaller Monte Carlo error in the estimate scale matrix.