| Title: | Compositional Data Analysis with the Zero Adjusted Dirichlet Distribution |
|---|---|
| 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>. |
| Authors: | Michail Tsagris [aut, cre] |
| Maintainer: | Michail Tsagris <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.0 |
| Built: | 2026-10-09 13:21:13 UTC |
| Source: | https://github.com/cran/CompositionalZADR |
Compositional Data Analysis with the Zero Adjusted Dirichlet Distribution. The package has extra capabilities not contained in the paper or the package "Compositional".
| Package: | CompositionalZADR |
| Type: | Package |
| Version: | 1.0 |
| Date: | 2026-08-20 |
Michail Tsagris <[email protected]>.
Michail Tsagris [email protected]
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 .
zad.contour(phi, mu, n = 100, y = NULL, cont.line = FALSE)zad.contour(phi, mu, n = 100, y = NULL, cont.line = FALSE)
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. |
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.
A ternary diagram with the points and the zero adjusted Dirichlet contour lines.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
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
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 )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.
dzad(y, phi, mu, logged = TRUE)dzad(y, phi, mu, logged = TRUE)
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. |
The density values of the zero adjusted Dirichlet distribution are computed.
A vector with the density values.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
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
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)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.
zad.mle(y)zad.mle(y)
y |
A matrix with the compositional data. |
A zero adjusted Dirichlet distribution is being fitted and its parameters are estimated.
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.. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
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
y <- as.matrix(iris[, 1:3]) y <- y / rowSums(y) y[sample(1:450, 15) ] <- 0 y <- y / rowSums(y) mod <- zad.mle(y)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.
rzad(n, phi, mu, patterns)rzad(n, phi, mu, patterns)
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. |
Random values from the zero adjusted Dirichlet distribution are generated.
A matrix with values generated from the zero adjusted Dirichlet distribution.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
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
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)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.
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)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)
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. |
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.
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, |
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 |
est |
The fitted or the predicted values (if xnew is not NULL). |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
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
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)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)