| gen_coda_with_zeros_and_missings | R Documentation |
Simulate compositional data and optionally introduce structural zeros (interpreted as values below a detection limit) and missing values.
The function first generates a compositional data set 'X0', then creates a modified version 'X' by:
replacing values below 'dl_par' by zero, if 'zeros = TRUE',
introducing missing values at random, if 'missings = TRUE'.
A matrix of detection limits 'DL' is also returned. It contains 'dl_par' in the positions that were censored to zero, and '0' elsewhere.
gen_coda_with_zeros_and_missings(
n,
d,
missings = TRUE,
zeros = TRUE,
dl_par = 0.05,
na_p = 0.15
)
n |
Number of observations. |
d |
Dimension of the latent coordinate space used to generate the compositions. |
missings |
Logical; if 'TRUE', introduce missing values at random. |
zeros |
Logical; if 'TRUE', replace values below 'dl_par' by zero. |
dl_par |
Detection-limit threshold used to generate zeros. |
na_p |
Probability that any entry is replaced by 'NA' when 'missings = TRUE'. |
Compositions are generated from multivariate normal coordinates and mapped to the simplex through 'composition()'. The eigenvector rotation is included to induce a non-trivial covariance structure in the generated coordinates.
Missing values are introduced completely at random, independently for each cell, with probability 'na_p'.
A list with three components:
The generated compositional data set with simulated zeros and/or missing values.
A matrix of detection limits, with 'dl_par' in censored positions and '0' elsewhere.
The original simulated compositional data set before introducing zeros or missing values.
set.seed(123)
sim <- gen_coda_with_zeros_and_missings(100, 4)
str(sim)
summary(sim$X0)
summary(sim$X)
table(sim$X == 0, useNA = "ifany")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.