Package {CompositionalZADR}


Type: Package
Title: Compositional Data Analysis with the Zero Adjusted Dirichlet Distribution
Version: 1.0
Date: 2026-08-20
Author: Michail Tsagris [aut, cre]
Maintainer: Michail Tsagris <mtsagris@uoc.gr>
Depends: R (≥ 4.0)
Imports: Compositional, graphics, grDevices, Rfast, stats
Suggests: Rfast2
Description: Regression, discriminant analysis, maximum likelihood estimation, random values generation, and contour plots of the zero adjusted Dirichlet distribution. The relevant paper is Tsagris M. and Stewart C. (2018). "A Dirichlet regression model for compositional data with zeros". Lobachevskii Journal of Mathematics, 39(3): 398–412. <doi:10.1134/S1995080218030198>.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
NeedsCompilation: no
Packaged: 2026-08-25 06:39:57 UTC; mtsag
Repository: CRAN
Date/Publication: 2026-09-07 11:20:02 UTC

Compositional Data Analysis with the Zero Adjusted Dirichlet Distribution

Description

Compositional Data Analysis with the Zero Adjusted Dirichlet Distribution. The package has extra capabilities not contained in the paper or the package "Compositional".

Details

Package: CompositionalZADR
Type: Package
Version: 1.0
Date: 2026-08-20

Maintainers

Michail Tsagris <mtsagris@uoc.gr>.

Author(s)

Michail Tsagris mtsagris@uoc.gr

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics, 39(3): 398–412.


Contour plot of the zero adjusted Dirichlet distribution in S^2

Description

Contour plot of the zero adjusted Dirichlet distribution in S^2.

Usage

zad.contour(phi, mu, n = 100, y = NULL, cont.line = FALSE)

Arguments

phi

A value with the concentration parameter.

mu

A vector with the mean vector (3 values) in the simplex.

n

The number of grid points to consider over which the density is calculated.

y

This is either NULL (no data) or contains a 3 column matrix with compositional data.

cont.line

Do you want the contour lines to appear? If yes, set this TRUE.

Details

The user can plot only the contour lines of a zero adjusted Dirichlet distribution with som given parameters, or can also add the relevant data should he/she wish to.

Value

A ternary diagram with the points and the zero adjusted Dirichlet contour lines.

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics, 39(3): 398–412.

Preprint available from https://arxiv.org/pdf/1410.5011.pdf

See Also

dzad

Examples

y <- as.matrix(iris[, 1:3])
y <- y / rowSums(y)
y[sample(1:450, 15) ] <- 0
y <- y / rowSums(y)
mod <- zad.mle(y)

zad.contour( phi = mod$phi, mu = mod$mu )

Density values of the zero adjusted Dirichlet distribution

Description

Density values of the zero adjusted Dirichlet distribution.

Usage

dzad(y, phi, mu, logged = TRUE)

Arguments

y

A matrix with compositional data with zero values.

phi

The concentration parameter.

mu

The mean vector.

logged

A boolean variable specifying whether the logarithm of the density values to be returned. It is set to TRUE by default.

Details

The density values of the zero adjusted Dirichlet distribution are computed.

Value

A vector with the density values.

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics, 39(3): 398–412.

Preprint available from https://arxiv.org/pdf/1410.5011.pdf

See Also

zad.mle, zadr

Examples

y <- as.matrix(iris[, 1:3])
y <- y / rowSums(y)
y[sample(1:450, 15) ] <- 0
y <- y / rowSums(y)
mod <- zad.mle(y)
f <- dzad(y, mod$phi, mod$mu)

MLE of the zero adjusted Dirichlet distribution

Description

MLE of the zero adjusted Dirichlet distribution.

Usage

zad.mle(y)

Arguments

y

A matrix with the compositional data.

Details

A zero adjusted Dirichlet distribution is being fitted and its parameters are estimated.

Value

A list including:

loglik

The value of the log-likelihood.

phi

The precision parameter. If covariates are linked with it (function "diri.reg2"), this will be a vector.

mu

The mean vector of the distribution.

patterns

A matrix with the patterns of zeros, where the value of 0 indicates the presence of a zero, and the last column contains the percentage of occurrence each pattern. This is useful for the random values simulation.

runtime

The time required by the model..

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics, 39(3): 398–412.

Preprint available from https://arxiv.org/pdf/1410.5011.pdf

See Also

zadr

Examples

y <- as.matrix(iris[, 1:3])
y <- y / rowSums(y)
y[sample(1:450, 15) ] <- 0
y <- y / rowSums(y)
mod <- zad.mle(y)

Random values simulation from the zero adjusted Dirichlet distribution

Description

Random values simulation from the zero adjusted Dirichlet distribution.

Usage

rzad(n, phi, mu, patterns)

Arguments

n

The number of compositional vectors to simulate.

phi

The concentration parameter.

mu

The mean vector.

patterns

A matrix with the patterns of zeros, where the value of 0 indicates the presence of a zero, and the last column contains the percentage of occurrence each pattern.

Details

Random values from the zero adjusted Dirichlet distribution are generated.

Value

A matrix with values generated from the zero adjusted Dirichlet distribution.

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics, 39(3): 398–412.

Preprint available from https://arxiv.org/pdf/1410.5011.pdf

See Also

zad.mle, zadr

Examples

y <- as.matrix(iris[, 1:3])
y <- y / rowSums(y)
y[sample(1:450, 15) ] <- 0
y <- y / rowSums(y)
mod <- zad.mle(y)
phi <- mod$phi
mu <- mod$mu
patterns <- mod$patterns
x <- rzad(100, phi, mu, patterns)

Zero adjusted Dirichlet regression

Description

Zero adjusted Dirichlet regression.

Usage

zadr(y, x, con = TRUE, xnew = NULL)
zadr2(y, x, con = TRUE, xnew = NULL)
zadr.irls(y, x, xnew = NULL, tol = 1e-6, maxit = 100)

Arguments

y

A matrix with the compositional data (dependent variable). The number of observations (vectors) with no zero values should be more than the columns of the predictor variables. Otherwise, the initial values will not be calculated.

x

The predictor variable(s), they can be either continnuous or categorical or both.

con

If this is TRUE (default) then the constant term is estimated, otherwise the model includes no constant term.

xnew

If you have new data use it, otherwise leave it NULL.

tol

The tolerance value to terminate the IRLS algorithm.

maxit

The maximum number of iterations allowed in the IRLS algortihm.

Details

A zero adjusted Dirichlet regression is being fitted. The likelihood conists of two components. The contributions of the non zero compositional values and the contributions of the compositional vectors with at least one zero value. The second component may have many different sub-categories, one for each pattern of zeros. The function "zadr2()" links the covariates to the alpha parameters of the Dirichlet distribution, i.e. it uses the classical parametrization of the distribution. This means, that there is a set of regression parameters for each component. The zadr.irls() function implements the IRLS algorithm.

Value

A list including:

runtime

The time required by the regression.

loglik

The value of the log-likelihood.

iters

The iterations required by the IRLS algorithm.

phi

The precision parameter, \phi.

be

The beta coefficients.

seb

The standard error of the beta coefficients.

sigma

Th covariance matrix of the regression parameters (for the mean vector and the \phi parameter).

est

The fitted or the predicted values (if xnew is not NULL).

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

References

Tsagris M. and Stewart C. (2018). A Dirichlet regression model for compositional data with zeros. Lobachevskii Journal of Mathematics,39(3): 398–412.

Preprint available from https://arxiv.org/pdf/1410.5011.pdf

See Also

zad.mle

Examples

x <- as.vector(iris[, 4])
y <- as.matrix(iris[, 1:3])
y <- y / rowSums(y)
y[sample(1:450, 15) ] <- 0
y <- y / rowSums(y)
mod2 <- zadr(y, x)