
Split cells into train/val/test for imputation evaluation
Source:R/mask_missing.R
make_missing_splits.RdRandomly selects a fixed number of originally observed trait units,
designates them as missing, and splits them into validation and test sets.
The requested holdout count is the floor of missing_frac times
the number of eligible observed units. Mechanism-specific weights affect
selection among those units; they are not per-cell Bernoulli
probabilities. For a "MAR_trait" design, keep the driver trait
observed if interpreting the design as missing at random.
When a trait_map is supplied, masking
operates at the original trait level – all latent columns belonging
to one trait are held out together (important for categorical traits).
Arguments
- X
numeric matrix (species x latent columns from
preprocess_traits). Existing missing values are excluded from the eligible holdout units. Values also determine weights for"MAR_trait"and"MNAR".- missing_frac
numeric. Fraction of all (species, trait) cells to designate as missing (default
0.25); the realised count is fixed from the eligible observed cells.- val_frac
numeric. Fraction of missing cells for validation (default
0.25); the rest become the test set.- seed
optional integer. When supplied, makes split construction reproducible; the default
NULLuses the current RNG stream.- trait_map
list of trait descriptors (from
pigauto_data). IfNULL, masking is applied per latent column (v0.1 behaviour).- mechanism
character. Missingness mechanism:
"MCAR"(default, uniform random),"MAR_trait"(trait-dependent),"MAR_phylo"(clade-structured), or"MNAR"(value-dependent).- mechanism_args
named list of mechanism-specific parameters:
- For
"MAR_trait": driver_col(integer, column index inXthat drives missingness; default 1),beta(numeric, severity; default 2.0). Selection weights depend on the observed driver values; keep the driver trait observed when interpreting the design as MAR.- For
"MAR_phylo": n_clades(integer, number of selected clades; default 2),p_clade(numeric, relative selection weight for cells within selected clades; default 0.7),p_base(numeric, relative selection weight for other cells; default 0.1). The fixed overall holdout count is sampled without replacement using these weights.- For
"MNAR": beta(numeric, severity; default 2.0).
- For
- tree
object of class
"phylo". Required formechanism = "MAR_phylo", ignored otherwise.
Value
A list with:
- val_idx
Integer vector of linear indices (latent space).
- test_idx
Integer vector of linear indices (latent space).
- val_idx_trait
Integer vector in original-trait space (if
trait_mapsupplied).- test_idx_trait
Integer vector in original-trait space (if
trait_mapsupplied).- n
Number of species (rows).
- p
Number of latent columns.
- n_traits
Number of original traits.
- mask
Logical matrix (n x p_latent).
TRUEmeans not artificially held out; it includes cells that were originally missing inX. Combine with!is.na(X)to identify observed training cells.- mechanism
Character string of the mechanism used.