Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mlysy/mniw
Simulation and Inference with the Matrix-Normal-Inverse-Wishart Distribution.
https://github.com/mlysy/mniw
Last synced: 3 months ago
JSON representation
Simulation and Inference with the Matrix-Normal-Inverse-Wishart Distribution.
- Host: GitHub
- URL: https://github.com/mlysy/mniw
- Owner: mlysy
- License: gpl-3.0
- Created: 2017-08-11T15:43:41.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-20T13:49:39.000Z (4 months ago)
- Last Synced: 2024-10-28T17:24:05.879Z (3 months ago)
- Language: C++
- Homepage: https://mlysy.github.io/mniw/
- Size: 608 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mniw: The Matrix-Normal Inverse-Wishart Distribution
*Martin Lysy, Bryan Yates*
[![R-CMD-check](https://github.com/mlysy/mniw/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mlysy/mniw/actions/workflows/R-CMD-check.yaml)
---
### Description
Density evaluation and random number generation for the Matrix-Normal Inverse-Wishart (MNIW) distribution, as well as the the Matrix-Normal, Matrix-T, Wishart, and Inverse-Wishart distributions. Core calculations are implemented in a portable (header-only) C++ library, with matrix manipulations using the [**Eigen**](http://eigen.tuxfamily.org/index.php?title=Main_Page) library for linear algebra. Also provided is a Gibbs sampler for Bayesian inference on a random-effects model with Matrix-Normal observations.
### Installation
To install the CRAN version (1.0.1):
``` r
install.packages("mniw", INSTALL_opts = "--install-tests")
```To install the latest development version: first install the [**devtools**](https://CRAN.R-project.org/package=devtools), then:
```r
devtools::install_github("mlysy/mniw", INSTALL_opts = "--install-tests")
```### Usage
The primary advantage of the **mniw** package is that it "vectorizes" over its input arguments. Take for example the simulation of a Wishart distribution, which can be done with the built-in R function `stats::rWishart()`:
```r
n <- 10
p <- 3
nu <- 6
# produces an array of size p x p x n
Psi <- stats::rWishart(n = n, df = nu, Sigma = diag(p))
```Now suppose we want to generate Wishart random variables each with a different `Sigma`:
```r
# Vectorizing over the 'Sigma' argument
X <- apply(Psi, 3, stats::rWishart, n = 1, df = nu)
X <- array(X, dim = c(p, p, n))
```However, the code above is both slow for large `n`, and inconvenient due to the reshaping of the `apply()` output. The equivalent code using **mniw** is:
```r
X <- rwish(n, df = nu, Psi = Psi) # produces an array of size p x p x n
```It is both simpler, and much faster for large `n` and `p`.
The other functions in **mniw** behave much the same way. A complete description of the distributions provided by the package is available [here](https://mlysy.github.io/mniw/articles/mniw-distributions.html).