README.md

rdirdirgamma

This package contains optimized code to sample from Dirichlet distribution, a specific hierarchical model (Dirichlet-Dirichlet-Gamma), and to perform ABC. Sampling is performed using Rcpp / RcppGSL. It has been written as part of my PhD thesis.

Disclaimer

Code is provided as an exercise, do not expect it to be bug-free. Feel free to adapt, modify and reuse the code!

Installation

You can install the development package from the GitHub repository:

remotes::install_github("lgaborini/rdirdirgamma")

Requirements

This package requires GSL libraries. On Linux/Mac it should work without problems.

On Windows, one needs to install them separately (refs: 1, 2):

  1. download the local323.zip package from here and extract it somewhere.
  2. create the environmental variable LIB_GSL and point to the extracted path (e.g. C:/local323_LIB_GSL). You can do it using the .Renviron file, either project-wide or user-wide (%HOME%/.Renviron): open it quickly with usethis::edit_r_environ().
  3. be sure that the file src/Makevars.win reads the GSL settings:
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib/x64 -lgsl -lgslcblas

Contents

Dirichlet sampling

Sample from a Dirichlet distribution:


library(rdirdirgamma)

alpha <- c(1, 1, 1)

x <- rdirichlet_cpp(alpha = alpha)
x

Sample from a Dirichlet distribution using the stick-breaking definition:


library(rdirdirgamma)

n_samples <- 10
alpha <- c(1, 1, 1)

x <- rdirichlet_beta_cpp(n = n_samples, alpha = alpha)
x

TODO



lgaborini/rdirdirgamma documentation built on March 6, 2021, 3:05 p.m.