View source: R/contaminate_simplex.R
| contaminate_simplex | R Documentation |
Introduces cellwise contamination on the simplex by replacing individual raw parts with contaminated values and re-closing the composition.
contaminate_simplex(
x,
epsilon = 0.05,
delta = 10,
type = "multiplicative",
seed = NULL
)
x |
clean compositional data (n x D matrix or data.frame with positive values) |
epsilon |
per-cell contamination probability (default: 0.05) |
delta |
contamination factor (default: 10) |
type |
|
seed |
random seed for reproducibility |
For each cell independently, contamination occurs with probability
epsilon. Three contamination types are available:
"multiplicative" multiplies the cell by delta,
"replacement" sets the cell to delta, and
"additive" adds delta times the row median.
After contamination, affected rows are re-closed to preserve the original
row sums. The "multiplicative" type, with per-cell rate epsilon
and magnitude delta, matches the scale-invariant cellwise
contamination model used in the simulation study of Templ (2026).
A list with components:
x_contaminated |
the contaminated compositions (re-closed to same row sums) |
flags |
n x D logical matrix indicating which cells were contaminated |
epsilon |
contamination rate used |
Matthias Templ
Templ, M. (2026). Log-ratio propagation on the simplex: a theory of cellwise contamination for compositional data. arXiv 2605.31345.
cellPcaCoDa (the estimator this model is designed to
stress-test), constSum
data(arcticLake)
cont <- contaminate_simplex(arcticLake, epsilon = 0.1, delta = 10, seed = 42)
sum(cont$flags) # number of contaminated cells
rowSums(cont$x_contaminated) # should match rowSums(arcticLake)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.