
Simulate synthetic pXRF compositional data (Dirichlet)
Source:R/taphonomy.R
morie_taphonomy_simulate_pxrf.RdSynthetic data for testing/calibration ONLY – never a substitute for
real comparanda, and never write the output to inst/extdata. Portable
X-ray fluorescence yields elemental concentrations that are strictly
non-negative and closed (a composition on the simplex), so Gaussian noise is
the wrong model; this samples from a Dirichlet distribution instead.
A control profile (natural soil/bone matrix) and a treatment profile
(quicklime – heavily skewed to calcium) let you exercise the causal /
compositional pipeline before real scans exist.
Arguments
- n
Number of samples (rows).
- condition
"control"(natural) or"treatment"(lime).- elements
Character vector of element names (default Ca, P, Fe, Sr, Pb, Zn).
- alpha
Optional Dirichlet concentration vector (one per element). Defaults encode the control vs lime profiles; required if you pass custom
elements.- seed
Optional RNG seed.
- as_ppm
If
TRUE, scale proportions to parts-per-million summing tototal_ppm; else return proportions summing to 1.- total_ppm
Total for the ppm scaling (default 1e6).
Value
A data.frame: one column per element, plus condition
and lime_treatment (1 = treatment). Attributes elements,
alpha, and synthetic = TRUE are attached.
Details
Dirichlet variates are drawn via normalised Gamma (\(X_i \sim \mathrm{Gamma}(\alpha_i, 1)\), \(Y = X / \sum X\)) so no extra package is needed.
Examples
head(morie_taphonomy_simulate_pxrf(5, "treatment", seed = 1))
#> Ca P Fe Sr Pb Zn
#> 1 0.9160276 0.06498899 0.009709022 8.530101e-03 3.378336e-04 4.064105e-04
#> 2 0.9245194 0.05901579 0.010998388 3.742419e-03 1.585031e-03 1.389422e-04
#> 3 0.9266993 0.05568073 0.013866444 7.319622e-06 3.433476e-04 3.402894e-03
#> 4 0.9489989 0.04162588 0.006514353 7.521032e-05 6.500858e-08 2.785601e-03
#> 5 0.9189031 0.03840343 0.034643436 7.957533e-03 9.251798e-05 1.313421e-08
#> condition lime_treatment
#> 1 treatment 1
#> 2 treatment 1
#> 3 treatment 1
#> 4 treatment 1
#> 5 treatment 1