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

446

Version

0.2.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Dean Markwick

Last Published

November 23rd, 2018

Functions in dirichletprocess (0.2.2)

ClusterParameterUpdate

Update the cluster parameters of the Dirichlet process.
DirichletProcessBeta

Dirichlet process mixture of the Beta distribution.
DirichletProcessMvnormal

Create a Dirichlet mixture of multivariate normal distributions.
DirichletProcessMvnormal2

Create a Dirichlet mixture of multivariate normal distributions with semi-conjugate prior.
MixingDistribution

Create a mixing distribution object
Mvnormal2Create

Create a multivariate normal mixing distribution with semi conjugate prior
StickBreaking

The Stick Breaking representation of the Dirichlet process.
UpdateAlpha

Update the Dirichlet process concentration parameter.
ClusterComponentUpdate

Update the component of the Dirichlet process
ClusterLabelPredict

Predict the cluster labels of some new data.
DirichletProcessWeibull

Create a Dirichlet Mixture of the Weibull distribution
ExponentialMixtureCreate

Create a Exponential mixing distribution
PosteriorDraw

Draw from the posterior distribution
PosteriorFrame

Calculate the posterior mean and quantiles from a Dirichlet process object.
PriorDraw

Draw from the prior distribution
PriorParametersUpdate

Update the prior parameters of a mixing distribution
DirichletProcessGaussian

Create a Dirichlet Mixture of Gaussians
DirichletProcessHierarchicalBeta

Create a Hierarchical Dirichlet Mixture of Beta Distributions
Fit

Fit the Dirichlet process object
GaussianMixtureCreate

Create a Normal mixing distribution
BetaMixtureCreate

Create a Beta mixing distribution.
ChangeObservations

Change the observations of fitted Dirichlet Process.
LikelihoodDP

The likelihood of the Dirichlet process object
Initialise

Initialise a Dirichlet process object
LikelihoodFunction

The Likelihood function of a Dirichlet process object.
plot.dirichletprocess

Plot the Dirichlet process object
rats

Tumour incidences in rats
Likelihood

Mixing Distribution Likelihood
DirichletProcessCreate

Create a Dirichlet Process object
DirichletProcessExponential

Create a Dirichlet Mixture of Exponentials
PosteriorFunction

Generate the posterior function of the Dirichlet function
PosteriorParameters

Calculate the posterior parameters for a conjugate prior.
GlobalParameterUpdate

Update the parameters of the hierarchical Dirichlet process object.
HierarchicalBetaCreate

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

Calculate how well the prior predicts the data.
PriorDensity

Calculate the prior density of a mixing distribution
weighted_function_generator

Generate a weighted function.
MvnormalCreate

Create a multivariate normal mixing distribution
PosteriorClusters

Generate the posterior clusters of a Dirichlet Process
WeibullMixtureCreate

Create a Weibull mixing distribution.
dirichletprocess

A flexible package for fitting Bayesian non-parametric models.