Ratio-of-Uniforms Simulation with Transformation

Uses the generalized ratio-of-uniforms (RU) method to simulate from univariate and (low-dimensional) multivariate continuous distributions. The user specifies the log-density, up to an additive constant. The RU algorithm is applied after relocation of mode of the density to zero, and the user can choose a tuning parameter r. For details see Wakefield, Gelfand and Smith (1991) , Efficient generation of random variates via the ratio-of-uniforms method, Statistics and Computing (1991) 1, 129-133. A Box-Cox variable transformation can be used to make the input density suitable for the RU method and to improve efficiency. In the multivariate case rotation of axes can also be used to improve efficiency. From version 1.2.0 the 'Rcpp' package < https://cran.r-project.org/package=Rcpp> can be used to improve efficiency.


rust rust logo

R-CMD-check CoverageStatus CRAN_Status_Badge Downloads(monthly) Downloads(total)

See also RUSampling for a translation of rust into Python, courtesy of Lynne Jewson.

Ratio-of-uniforms simulation with transformation

What does rust do?

The rust package implements the multivariate generalized ratio-of-uniforms method of simulating random variates from a d-dimensional continuous distribution. The user specifies (the log of) a positive target function f that is proportional to the density function of the distribution.

A simple example

We use the function ru to simulate a sample of size 1000 from a two-dimensional standard normal distribution with strong positive correlation between the components. Of course, this particular example is purely illustrative: there are better ways to simulate from a multivariate normal distribution.

rho <- 0.9
covmat <- matrix(c(1, rho, rho, 1), 2, 2)
log_dmvnorm <- function(x, mean = rep(0, d), sigma = diag(d)) {
  x <- matrix(x, ncol = length(x))
  d <- ncol(x)
  - 0.5 * (x - mean) %*% solve(sigma) %*% t(x - mean)
}
x <- ru(logf = log_dmvnorm, sigma = covmat, d = 2, n = 1000, init = c(0, 0))

From version 1.2.0 onwards the faster function ru_rcpp can be used. See the vignette “Rusting Faster: Simulation using Rcpp” for details.

# Create an external pointer to a C++ function to evaluate the log-density.
ptr_bvn <- create_xptr("logdnorm2")
# Pass the external pointer to `ru_rcpp`.
x <- ru_rcpp(logf = ptr_bvn, rho = rho, d = 2, n = 1000, init = c(0, 0))

Installation

To get the current released version from CRAN:

install.packages("rust")

Vignettes

See vignette("rust-a-vignette", package = "rust") for an overview of the package, vignette("rust-b-when-to-use-vignette", package = "rust") for guidance on when rust can be used and vignette("rust-c-using-rcpp-vignette", package = "rust") for information on how to take advantage of the Rcpp package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rust")

1.4.4 by Paul J. Northrop, 9 months ago


https://paulnorthrop.github.io/rust/, https://github.com/paulnorthrop/rust


Report a bug at https://github.com/paulnorthrop/rust/issues


Browse source code at https://github.com/cran/rust


Authors: Paul J. Northrop [aut, cre, cph]


Documentation:   PDF Manual  


GPL (>= 2) license


Imports graphics, Rcpp, stats

Suggests bang, knitr, microbenchmark, revdbayes, rmarkdown, testthat

Linking to Rcpp, RcppArmadillo


Imported by bang, evmissing, fitdistcp, lite, revdbayes, threshr.


See at CRAN