Description Usage Arguments Details Value Author(s) Examples
Computes a scale matrix in the BUGS parameterization that corresponds to a minimally-informative Wishart prior distribution for a precision matrix, with the property that the medians of the diagonals of the implied prior distribution for the corresponding covariance matrix are approximately equal to specified target variances.
1 | get_bugs_wishart_scalemat(target, nsim=25000, reltol = 0.05, quietly=TRUE)
|
target |
A |
nsim |
Number of Monte-Carlo simulations used to set target scale matrix. Default is 25,000. |
reltol |
Relative tolerance determining when the algorithm stops trying to find a better scale matrix. Default is 0.05. |
quietly |
If |
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.
A list with elements
bugs.df: Degrees of freedom to use for Wishart prior
distribution in BUGS, equal to p+1
where p
is the
dimension of target
.
bugs.scalemat: Scale matrix to use for Wishart prior distribution in BUGS.
varsum: Summary of prior distribution of implied variances;
medians should approximately equal target
.
corsum: Summary of prior distribution of implied correlations.
J.R. Lockwood jrlockwood@ets.org
1 2 3 4 5 6 7 8 | tmp <- get_bugs_wishart_scalemat(target = c(10,4,4,8), nsim = 30000,
reltol = 0.02, quietly=FALSE)
print(tmp)
## if you now model precison matrix M ~ dwish(tmp$bugs.scalemat,
## tmp$bugs.df) in a BUGS language, this will imply a prior distribution
## for the inverse of M that has medians of the diagonal elements
## approximately equal to 'target'
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.