View source: R/zero_replacement_imputation.R
coda_replacement | R Documentation |
Performs imputation (replacement) of missing values and/or values below the detection limit (BDL) in compositional datasets using the EM-algorithm assuming normality on the Simplex. This function is designed to prepare compositional data for subsequent log-ratio transformations.
coda_replacement(
X,
DL = NULL,
dl_prop = 0.65,
eps = 1e-04,
parameters = FALSE,
debug = FALSE
)
X |
A compositional dataset: numeric matrix or data frame where rows represent observations and columns represent parts. |
DL |
An optional matrix or vector of detection limits. If |
dl_prop |
A numeric value between 0 and 1, used for initialization in the EM algorithm (default is 0.65). |
eps |
A small positive value controlling the convergence criterion for the EM algorithm (default is |
parameters |
Logical. If |
debug |
Logical. Show the log-likelihood in every iteration. |
- Missing values are imputed based on a multivariate normal model on the simplex.
- Zeros are treated as censored values and replaced accordingly.
- The EM algorithm iteratively estimates the missing parts and model parameters.
- To initialize the EM algorithm, zero values (considered below the detection limit) are replaced with a small positive value. Specifically, each zero is replaced by dl_prop
times the detection limit of that part (column). This restrictions is imposed in the geometric mean of the parts with zeros against the non-missing positive values, helping to preserve the compositional structure in the simplex.
If parameters = FALSE
, returns a numeric matrix with imputed values.
If parameters = TRUE
, returns a list with two components:
The imputed compositional data matrix.
A list containing information about the EM algorithm parameters and convergence diagnostics.
# Simulate compositional data with zeros
set.seed(123)
X <- abs(matrix(rnorm(100), ncol = 5))
X[sample(length(X), 10)] <- 0 # Introduce some zeros
X[sample(length(X), 10)] <- NA # Introduce some NAs
# Apply replacement
summary(X/rowSums(X, na.rm=TRUE))
summary(coda_replacement(X))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.