dsample | R Documentation |
dsample
generates a sample of specified size n
from the target density function (up to a normalizing constant) based on the Wang-Lee algorithm.
dsample(expr, rpmat, n = 1000, nk = 10000, wconst)
expr |
expression of a target density function |
rpmat |
matrix containing random points for discretization |
n |
non-negative integer, the desired sample size. |
nk |
positive integer, the number of contours. See ‘Details’. |
wconst |
real number between 0 and 1. See ‘Details’. |
X
has the number of rows equals to the number of discrete base points. In each row, the first element contains the functional value of the target density and the rest elements are the coordinates at which the density is evaluated.
wconst
is a constant for adjusting the volume of the last contour.
dsample
gives the samples in data.frame
with number of rows n
and number of columns ncol(rpmat)
.
Wang, L. and Lee, C.H. (2014). Discretization-based direct random sample generation. Computational Statistics and Data Analysis, 71, 1001-1010. Lee, C.H. (2009). Efficient Monte Carlo Random Sample Generation through Discretization, MSc thesis, Department of Satistics, University of Manitoba, Canada
## Example on page 414 in West (1993) expr <- expression((x1*(1-x2))^5 * (x2*(1-x1))^3 * (1-x1*(1-x2)-x2*(1-x1))^37) sets <- list(x1=runif(1e3), x2=runif(1e3)) smp <- dsample(expr=expr, rpmat=sets, nk=1e2, n=1e3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.