Package {Compositionalzerocens}


Type: Package
Title: Modelling Zero Values in Compositional Data Using a Censored Model
Version: 1.1
Date: 2026-09-28
Author: Michail Tsagris [aut, cre]
Maintainer: Michail Tsagris <mtsagris@uoc.gr>
Depends: R (≥ 4.0)
Imports: Compositional, far, Rfast, stats, TruncatedNormal
Suggests: Rfast2
Description: Modelling structural zeros in compositional data assuming a latent Gaussian model, where MLE is performed via the EM algorithm. The relevant paper is Tsagris and Alharbi (2026) <doi:10.48550/arXiv.2208.13073>.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
NeedsCompilation: no
Packaged: 2026-09-28 19:39:46 UTC; mtsag
Repository: CRAN
Date/Publication: 2026-09-29 10:20:16 UTC

Modelling Zero Values in Compositional Data Using a Censored Model

Description

Modelling Zero Values in Compositional Data Using a Censored Model.

Details

Package: Compositionalzerocens
Type: Package
Version: 1.1
Date: 2026-09-28

Maintainers

Michail Tsagris <mtsagris@uoc.gr>.

Author(s)

Michail Tsagris mtsagris@uoc.gr

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073


Density of the zero-censored model

Description

Density of the zero-censored model.

Usage

dzerocens(x, mu, sigma, logdens = FALSE)

Arguments

x

A vector or a matrix with compositional data.

mu

The mean vector in R^{D-1}.

sigma

The covariance matrix in R^{D-1}.

logdens

If you want the log of the density set this TRUE, otherwise leave it FALSE.

Details

The function computes the density values of the zero-censored model.

Value

The density values at the given compositional data x.

Author(s)

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

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073

Examples

mu <- c(0.325, 0.121)
sigma <- matrix(c(0.149, -0.200,
                  -0.200,  0.323), 2, 2)
x <- rzerocens(100, mu, sigma)
mod <- zerocens.em(x)
mu <- mod$mu
sigma <- mod$sigma
f <- dzerocens(x, mu, sigma)

Goodness-of-fit test for the zero-censored model

Description

Goodness-of-fit test for the zero-censored model.

Usage

gof.zerocens(x, mu, sigma, B = 999, nsim = 1e+6)

Arguments

x

A a matrix with compositional data.

mu

The mean vector in R^{D-1}.

sigma

The covariance matrix in R^{D-1}.

B

The number of bootstrap samples to generate.

nsim

The number of draws to use in the Monte Carlo estimation of the zero-censoring probability.

Details

The function performs a goodness-of-fit test for the observed number of zero patterns (Tsagris and Alharbi, 2026).

Value

The p-value of the test.

Author(s)

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

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073

Examples

mu <- c(0.325, 0.121)
sigma <- matrix( c(0.149, -0.200, -0.200,  0.323), ncol = 2)
x <- rzerocens(100, mu, sigma)
gof.zerocens(x, mu, sigma, B = 49, nsim = 1e+3)

Estimation of the zero-censoring probability

Description

Estimation of the zero-censoring probability.

Usage

prob.zerocens(mu, sigma, theoretical = FALSE, nsim = 1e+6)

Arguments

mu

The mean vector in R^{D-1}.

sigma

The covariance matrix in R^{D-1}.

theoretical

Do you want the theoretical probability?

nsim

The number of draws to use in the Monte Carlo estimation of the zero-censoring probability.

Details

The function performs a goodness–of–fit test for the zero-censored model via a simulated \chi^2 test using parametric bootstrap (Tsagris and Alharbi, 2026).

Value

The (theoretical) probability of zero-censoring at each component.

Author(s)

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

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073

Examples

mu <- c(0.325, 0.121)
sigma <- matrix(c(0.149, -0.200,
                  -0.200,  0.323), 2, 2)
prob.zerocens(mu, sigma, theoretical = TRUE)

Maximum likelihood estimation of the zero-censored model

Description

Maximum likelihood estimation of the zero-censored model.

Usage

rzerocens(n, mu, sigma)

Arguments

n

The sample size.

mu

The mean vector in R^{D-1}.

sigma

The covariance matrix in R^{D-1}.

Details

The function generates compositional data from the cero-censored model (Tsagris and Alharbi, 2026). The drawback is that only 1 zero, at most, is allowed in each compositional vector.

Value

A numerical matrix with compositional data.

Author(s)

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

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073

Examples

mu <- c(0.325, 0.121)
sigma <- matrix(c(0.149, -0.200, -0.200,  0.323), ncol = 2)
x <- rzerocens(1000, mu, sigma)

Maximum likelihood estimation of the zero-censored model

Description

Maximum likelihood estimation of the zero-censored model.

Usage

zerocens.em(x, tol = 1e-6, maxit = 1000)
zerocens.mle(x)

Arguments

x

A numerical matrix with compositional data. Only one zero value is allowed in each row.

tol

The tolerance value to terminate the EM algorithm.

maxit

The maximum number of iterations allowed for the EM algorithm.

Details

The function fits the cero-censored model (Tsagris, 2026) to compositional data with zero values. The drawback is that only 1 zero, at most, is allowed in each compositional vector. The zerocens.em() function fits the model using the EM algorithm and it is quite efficient, whereas the second function, zerocens.mle() uses optim() and is quite slow.

Value

A list including:

loglik

The log-likelihood value.

iters

The number of iterations required by the EM algorithm.

mu

The estimated mean vector.

sigma

The estimated covariance matrix.

Author(s)

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

References

Tsagris M. and Alharbi N. (2026). Modelling structural zeros in compositional data via a zero-censored multivariate normal model.

https://arxiv.org/pdf/2208.13073

Examples

mu <- c(0.325, 0.121)
sigma <- matrix(c(0.149, -0.200,
                  -0.200,  0.323), 2, 2)
x <- rzerocens(100, mu, sigma)
zerocens.em(x)
zerocens.mle(x)