get_bugs_wishart_scalemat: Compute a BUGS-compliant scale matrix for a Wishart prior...

View source: R/get_bugs_wishart_scalemat.R

get_bugs_wishart_scalematR Documentation

Compute a BUGS-compliant scale matrix for a Wishart prior distribution for precision matrix that is consistent with target variances.

Description

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.

Usage

get_bugs_wishart_scalemat(target, nsim=25000, reltol = 0.05, quietly=TRUE)

Arguments

target

A p-dimensional vector of target variances. These are the variances that you would like your BUGS Wishart prior distribution to support.

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 quietly is FALSE, prints iterative and final diagnostic information. Default is TRUE.

Details

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.

Value

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.

Author(s)

J.R. Lockwood jrlockwood@ets.org

Examples


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'


jrlockwood/eivtools documentation built on April 9, 2022, 4:01 a.m.