Build Dirichlet Process Objects for Bayesian Modelling

Perform nonparametric Bayesian analysis using Dirichlet processes without the need to program the inference algorithms. Utilise included pre-built models or specify custom models and allow the 'dirichletprocess' package to handle the Markov chain Monte Carlo sampling. Our Dirichlet process objects can act as building blocks for a variety of statistical models including and not limited to: density estimation, clustering and prior distributions in hierarchical models. See Teh, Y. W. (2011) <>, among many other sources.

Travis-CI Build Status AppVeyor Build Status Coverage Status

The dirichletprocess package provides tools for you to build custom Dirichlet process mixture models. You can use the pre-built Normal/Weibull/Beta distributions or create your own following the instructions in the vignette. In as little as four lines of code you can be modelling your data nonparametrically.


You can install the stable release of dirichletprocess from CRAN:


You can also install the development build of dirichletprocess from github with:


For a full guide to the package and its capabilities please consult the vignette:

browseVignettes(package = "dirichletprocess")


Density Estimation

Dirichlet processes can be used for nonparametric density estimation.

faithfulTransformed <- faithful$waiting - mean(faithful$waiting)
faithfulTransformed <- faithfulTransformed/sd(faithful$waiting)
dp <- DirichletProcessGaussian(faithfulTransformed)
dp <- Fit(dp, 100, progressBar = FALSE)

data.frame(Weight=dp$weights, Mean=c(dp$clusterParameters[[1]]), SD=c(dp$clusterParameters[[1]]))
#>        Weight       Mean         SD
#> 1 0.371323529 -1.1756510 -1.1756510
#> 2 0.625000000  0.6597522  0.6597522
#> 3 0.003676471  0.1061095  0.1061095


Dirichlet processes can also be used to cluster data based on their common distribution parameters.

faithfulTrans <- as.matrix(apply(faithful, 2, function(x) (x-mean(x))/sd(x)))
dpCluster <-  DirichletProcessMvnormal(faithfulTrans)
dpCluster <- Fit(dpCluster, 1000, progressBar = FALSE)

To plot the results we take the cluster labels contained in the dp object and assign them a colour

For more detailed explanations and examples see the vignette.


dirichletprocess 0.2.2

  • Added a likelihood variable for the dirichletprocess class that is calculate with each fit iteration.
  • Added option to change how many Metropolis-Hasting steps are used in each iteration.
  • Added a likelihood calculation with each iteration.
  • Added and refactored some tests.
  • Updated vignette.
  • Additional options to univariate plotting.
  • Added Kees Mulder as a contributor.

dirichletprocess 0.2.1

  • Added AppVeyor, Travis-CI and badges.
  • Added penalised log-likelihood step for posterior cluster parameter inference.
  • Added exponential mixture model DirichletProcessExponential.
  • Updated plot. Multivariate Gaussian models can now be plotted.
  • Various bug fixes.
  • Updated description.

dirichletprocess 0.2.0

  • First public release.
  • Added a file to track changes to the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.3.1 by Dean Markwick, 2 months ago

Report a bug at

Browse source code at

Authors: Gordon J. Ross [aut] , Dean Markwick [aut, cre] , Kees Mulder [ctb]

Documentation:   PDF Manual  

GPL-3 license

Imports gtools, ggplot2, mvtnorm

Suggests testthat, knitr, rmarkdown, tidyr, dplyr

See at CRAN