coda_replacement: Replacement of missing values and below-detection zeros in...

View source: R/zero_replacement_imputation.R

coda_replacementR Documentation

Replacement of missing values and below-detection zeros in compositional data

Description

Performs imputation of missing values and/or values below the detection limit in compositional data using an EM algorithm assuming normality on the simplex.

Usage

coda_replacement(
  X,
  DL = NULL,
  dl_prop = 0.65,
  eps = 1e-04,
  parameters = FALSE,
  debug = FALSE,
  maxit = 500
)

Arguments

X

A compositional data set: numeric matrix or data frame where rows represent observations and columns represent parts.

DL

An optional matrix or vector of detection limits. If 'NULL', the minimum non-zero value in each column of 'X' is used.

dl_prop

A numeric value between 0 and 1 used for initialization in the EM algorithm.

eps

Convergence tolerance.

parameters

Logical; if 'TRUE', return additional estimated parameters.

debug

Logical; if 'TRUE', print the log-likelihood at each iteration.

maxit

Maximum number of iterations

Value

If 'parameters = FALSE', the imputed object with the same format as 'X' ('matrix' or 'data.frame', preserving data-frame subclasses when possible) and preserving original names. If 'parameters = TRUE', a list with the estimated clr mean, clr covariance, and imputed clr coordinates.

Examples

X <- matrix(c(
  0.00, 0.30, 0.70,
  0.20,   NA, 0.80,
  0.40, 0.60, 0.00,
  0.25, 0.25, 0.50,
  0.10, 0.30, 0.60
), ncol = 3, byrow = TRUE)
colnames(X) <- c("sand", "silt", "clay")

DL <- c(0.05, 0.05, 0.05)

X_imp <- coda_replacement(X, DL = DL, maxit = 20)
X_imp

set.seed(10)
X <- composition(matrix(rnorm(3*10), ncol = 3))
X[sample(c(TRUE, FALSE), 4*10, replace = TRUE, c(1, 3))] <- NA
params <- coda_replacement(X, parameters = TRUE, debug = TRUE)
names(params)
params$clr_mu
composition(params$clr_h)

coda.base documentation built on May 8, 2026, 5:10 p.m.