ars | R Documentation |
Generates a sequence of random variables using Adaptive Rejection Sampling (ARS).
ars(logpdf, n = 1, lower=-14, upper=15, x0 = 0, ...)
arns(logpdf, n = 1, lower = -5, upper = 5, sigma.offset = 0.05,
fx.offset = 0.03, K = 100, verbose = FALSE, ...)
n |
Desired sample size. |
x0 |
Initial point. |
logpdf |
Univariate log target density. |
lower |
lower limit of the random variable. |
upper |
upper limit of the random variable. |
sigma.offset |
offset of sigma for the normal envelope function to ensure it covers the logpdf. |
fx.offset |
offset of maximum for the normal envelope function to ensure it covers the logpdf. |
K |
number of points between lower and upper to evaluate logpdf to find the peak and bottom values. |
verbose |
print out the verbose, default is FALSE. |
... |
Parameters passed to |
The support of the target density must be a bounded convex set. When this is not the case, the following tricks usually work. If the support is not bounded, restrict it to a bounded set having probability practically one. A workaround, if the support is not convex, is to consider the convex set generated by the support.
Make sure the value returned by logpdf
is never smaller than
log(.Machine$double.xmin)
, to avoid divisions by zero.
An n
vector, whose elements are the sampled points.
Bingshu E. Chen bingshu.chen@queensu.ca
Gilks, W.R., Best, N.G. and Tan, K.K.C. (1995) Adaptive rejection Metropolis sampling within Gibbs sampling (Corr: 97V46 p541-542 with Neal, R.M.), Applied Statistics 44:455–472.
#### ==> Warning: running the examples may take a few minutes! <== ####
### Univariate densities
## Normal(mean,1)
norldens <- function(x, mean) -(x-mean)^2/2
y <- ars(10, norldens, mean=10, upper = 30)
summary(y);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.