Skip to content

R package to sample from a Dirichlet-Dirichlet-Gamma hierarchical model

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

lgaborini/rdirdirgamma

Repository files navigation

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

  • Complete README
  • Improve time-based RNG in GSL: set the seed once
  • Fix segfault when sampling ABC using the unstable Dirichlet definition
  • Implement ABC tests
  • Better parameter checking