Description Details Author(s) Examples
The SALTSampler package facilitates Monte Carlo Markov Chain (MCMC) sampling of random variables on a simplex. A Self-Adjusting Logit Transform (SALT) proposal is used so that sampling is still efficient even in difficult cases, such as those in high dimensions or with parameters that differ by orders of magnitude. Special care is also taken to maintain accuracy even when some coordinates approach 0 or 1 numerically. Diagnostic and graphic functions are included in the package, enabling easy assessment of the convergence and mixing of the chain within the constrained space.
Package: | SALTSampler |
Type: | Package |
Version: | 0.1 |
Date: | 2015-08-15 |
License: | BSD_3_clause + file LICENSE |
The main function for this package is runMh
. Using user-defined information, runMh
conducts MCMC on a simplex and outputs an object of class mhRun
. The function can be used with any target distribution on the simplex defined by the user. Alternatively, two common posteriors types are built into the function and can be specifed by the user. For type 'dirichlet'
, mhRun
produces MCMC samples from a specified dirichlet distribution and for type 'multinomial'
, mhRun
uses data to sample the distributional parameters of a multinomial distribution. Additionally, the functions Diagnostics
and TriPlot
can be used to analyze the output of mhRun
.
Hannah Director, Scott Vander Wiel, Jim Gattiker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ###Dirichlet sampling in 3-simplex
dir <- RunMh(center = c(0.7, 0.2, 0.1), B = 2e3, concentration = 10,
h = c(2, 2, 2), type = 'dirichlet', dat = NULL)
Diagnostics(mhOut = dir)
TriPlot(mhOut = dir)
####Multinomial sampling
## Not run:
sampData <- GenData(center = c(0.2, 0.3, 0.5), n = 100, size = 10)
multinom <- RunMh(center = c(0.2, 0.3, 0.5), B = 1e4, h = c(2,2,2),
type = 'multinom', dat = sampData)
Diagnostics(mhOut = multinom)
TriPlot(mhOut = multinom)
## End(Not run)
####User-defined target distribution for a calibration problem
## Not run:
#Known function which we want to calibrate
CalibFn <- function(y, logit = FALSE) {
if (logit == TRUE) {
y <- exp(LogPq(y)$logp)
}
out <- 1e3*y[1]^3*y[2]^3/sqrt(20 + y[3])
return(out)
}
#Generated data
z <- rnorm(n = 1000, mean = CalibFn(c(1/3, 1/3, 1/3), 2))
#User defined target distribution
Target <- function(ycand, ycurrent, a, dat, pars = NULL) {
out <- sum(dnorm(z, CalibFn(ycand, logit = TRUE), 2, log = TRUE)) -
sum(dnorm(z, CalibFn(ycurrent, logit = TRUE), 2, log = TRUE)) +
sum((a - 1)*(LogPq(ycand)$logp - LogPq(ycurrent)$logp))
return(out)
}
#Run sampler
inputDist <- RunMh(center = c(1/3, 1/3, 1/3), B = 3e4, concentration = 3,
h = c(0.2, 0.2, 0.2), type = 'user', dat = z)
Diagnostics(mhOut = inputDist)
TriPlot(mhOut = inputDist)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.