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 non-parametrically.

Installation

You can install 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 non-parametric 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

441

Version

0.2.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Dean Markwick

Last Published

January 29th, 2018

Functions in dirichletprocess (0.2.0)

BetaMixtureCreate

Create a Beta mixing distribution.
ChangeObservations

Change the observations of fitted Dirichlet Process.
DirichletProcessHierarchicalBeta

Create a Hierarchical Dirichlet Mixture of Beta Distributions
DirichletProcessMvnormal

Create a Dirichlet mixture of multivariate normal distributions.
GaussianMixtureCreate

Create a Normal mixing distribution
GlobalParameterUpdate

Update the parameters of the hierarchical Dirichlet process object.
PriorDraw

Draw from the prior distribution
PriorParametersUpdate

Update the prior parameters of a mixing distribution
DirichletProcessCreate

Create a Dirichlet Process object
DirichletProcessGaussian

Create a Dirichlet Mixture of Gaussians
PosteriorClusters

Generate the posterior clusters of a Dirichlet Process
PosteriorDraw

Draw from the posterior distribution
DirichletProcessWeibull

Create a Dirichlet Mixture of the Weibull distribution
Fit

Fit the Dirichlet process object
PosteriorFunction

Generate the posterior function of the Dirichlet function
PosteriorParameters

Calculate the posterior parameters for a conjugate prior.
WeibullMixtureCreate

Create a Weibull mixing distribution.
ClusterParameterUpdate

Update the cluster parameters of the Dirichlet process.
DirichletProcessBeta

Dirichlet process mixture of the Beta distribution.
MixingDistribution

Create a mixing distribution object
ClusterComponentUpdate

Update the component of the Dirichlet process
ClusterLabelPredict

Predict the cluster labels of some new data.
Likelihood

Mixing Distribution Likelihood
MvnormalCreate

Create a multivariate normal mixing distribution
StickBreaking

The Stick Breaking representation of the Dirichlet process.
UpdateAlpha

Update the Dirichlet process concentration parameter.
plot.dirichletprocess

Plot the Dirichlet Process
LikelihoodFunction

The Likelihood of a Dirichlet process object.
Predictive

Calculate how well the prior predicts the data.
PriorDensity

Calculate the prior density of a mixing distribution
HierarchicalBetaCreate

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

Initialise a Dirichlet process object
weighted_function_generator

Generate a weighted function.
dirichletprocess

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

Tumour incidences in rats