Learn R Programming

⚠️There's a newer version (0.4.2) of this package.Take me there.

dirichletprocess

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.

Installation

You can install the stable release of dirichletprocess from CRAN:

install.packages("dirichletprocess")

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

# install.packages("devtools")
devtools::install_github("dm13450/dirichletprocess")

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

browseVignettes(package = "dirichletprocess")

Examples

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)
plot(dp)

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

Clustering

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.

Copy Link

Version

Install

install.packages('dirichletprocess')

Monthly Downloads

384

Version

0.2.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Dean Markwick

Last Published

April 18th, 2018

Functions in dirichletprocess (0.2.1)

Initialise

Initialise a Dirichlet process object
Fit

Fit the Dirichlet process object
PosteriorClusters

Generate the posterior clusters of a Dirichlet Process
PosteriorFunction

Generate the posterior function of the Dirichlet function
PosteriorParameters

Calculate the posterior parameters for a conjugate prior.
PriorDensity

Calculate the prior density of a mixing distribution
weighted_function_generator

Generate a weighted function.
Predictive

Calculate how well the prior predicts the data.
MixingDistribution

Create a mixing distribution object
Likelihood

Mixing Distribution Likelihood
UpdateAlpha

Update the Dirichlet process concentration parameter.
PosteriorDraw

Draw from the posterior distribution
LikelihoodFunction

The Likelihood of a Dirichlet process object.
MvnormalCreate

Create a multivariate normal mixing distribution
StickBreaking

The Stick Breaking representation of the Dirichlet process.
plot.dirichletprocess

Plot the Dirichlet process object
WeibullMixtureCreate

Create a Weibull mixing distribution.
rats

Tumour incidences in rats
dirichletprocess

A flexible package for fitting Bayesian non-parametric models.
DirichletProcessExponential

Create a Dirichlet Mixture of Exponentials
ClusterParameterUpdate

Update the cluster parameters of the Dirichlet process.
ChangeObservations

Change the observations of fitted Dirichlet Process.
ClusterLabelPredict

Predict the cluster labels of some new data.
DirichletProcessHierarchicalBeta

Create a Hierarchical Dirichlet Mixture of Beta Distributions
ClusterComponentUpdate

Update the component of the Dirichlet process
DirichletProcessBeta

Dirichlet process mixture of the Beta distribution.
DirichletProcessGaussian

Create a Dirichlet Mixture of Gaussians
DirichletProcessCreate

Create a Dirichlet Process object
BetaMixtureCreate

Create a Beta mixing distribution.
ExponentialMixtureCreate

Create a Exponential mixing distribution
DirichletProcessMvnormal

Create a Dirichlet mixture of multivariate normal distributions.
DirichletProcessWeibull

Create a Dirichlet Mixture of the Weibull distribution
PriorParametersUpdate

Update the prior parameters of a mixing distribution
HierarchicalBetaCreate

Create a Mixing Object for a hierarchical Beta Dirichlet process object.
GaussianMixtureCreate

Create a Normal mixing distribution
PriorDraw

Draw from the prior distribution
GlobalParameterUpdate

Update the parameters of the hierarchical Dirichlet process object.