Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulnorthrop/rust
Ratio-of-Uniforms Simulation with Transformation.
https://github.com/paulnorthrop/rust
1977 bayesian-inference cran kinderman monahan of posterior-samples r ratio ratio-of-uniforms ratio-of-uniforms-method rcpp simulation transformation uniforms
Last synced: 9 days ago
JSON representation
Ratio-of-Uniforms Simulation with Transformation.
- Host: GitHub
- URL: https://github.com/paulnorthrop/rust
- Owner: paulnorthrop
- License: gpl-3.0
- Created: 2016-10-11T21:40:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-18T08:12:10.000Z (5 months ago)
- Last Synced: 2024-11-28T23:06:29.536Z (about 1 month ago)
- Topics: 1977, bayesian-inference, cran, kinderman, monahan, of, posterior-samples, r, ratio, ratio-of-uniforms, ratio-of-uniforms-method, rcpp, simulation, transformation, uniforms
- Language: R
- Homepage: https://paulnorthrop.github.io/rust/
- Size: 52.6 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```# rust
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/paulnorthrop/rust?branch=master&svg=true)](https://ci.appveyor.com/project/paulnorthrop/rust)
[![R-CMD-check](https://github.com/paulnorthrop/rust/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/paulnorthrop/rust/actions/workflows/R-CMD-check.yaml)
[![Coverage Status](https://codecov.io/github/paulnorthrop/rust/coverage.svg?branch=master)](https://app.codecov.io/github/paulnorthrop/rust?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rust)](https://cran.r-project.org/package=rust)
[![Downloads (monthly)](https://cranlogs.r-pkg.org/badges/rust?color=brightgreen)](https://cran.r-project.org/package=rust)
[![Downloads (total)](https://cranlogs.r-pkg.org/badges/grand-total/rust?color=brightgreen)](https://cran.r-project.org/package=rust)## 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.
```{r, eval = FALSE}
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.
```{r, eval = FALSE}
# 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:
```{r installation, eval = FALSE}
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.