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.
Code is provided as an exercise, do not expect it to be bug-free.
Feel free to adapt, modify and reuse the code!
You can install the development package from the GitHub repository:
remotes::install_github("lgaborini/rdirdirgamma")
This package requires GSL libraries.
On Linux/Mac it should work without problems.
On Windows, one needs to install them separately (refs: 1, 2):
- download the
local323.zip
package from here and extract it somewhere. - 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 withusethis::edit_r_environ()
. - 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
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
- 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