View source: R/unmix_mixsiar.R
| unmix_mixsiar | R Documentation |
A wrapper function that seamlessly formats an OceanTracer dataset (raw or averaged)
and passes it to the MixSIAR Bayesian unmixing engine.
unmix_mixsiar(
data,
tracers = NULL,
prior_type = "uninformative",
prior_values = NULL,
run = "normal",
process_err = FALSE,
resid_err = TRUE
)
data |
Data frame. Contains source and mixture data in standard OceanTracer format. |
tracers |
Character vector. Names of the tracers to include in the model. Default is |
prior_type |
Character. |
prior_values |
Numeric vector. Required if |
run |
Character. MCMC run length. Options: |
process_err |
Logical. Include process error in the JAGS model? Default |
resid_err |
Logical. Include residual error in the JAGS model? Default |
A named list containing:
apportionment |
A data frame with posterior draw proportions for each source, formatted for |
bayesian_summary |
A data frame summarizing MCMC parameter posteriors (mean, SD, quantiles, Rhat). |
jags_model |
The raw |
# Requires the external JAGS C++ library and MixSIAR R package installed
if (requireNamespace("MixSIAR", quietly = TRUE)) {
# Sample dataset in OceanTracer raw format
raw_data <- data.frame(
ID = paste0("Sample_", 1:9),
Group = rep(c("Source_A", "Source_B", "Mix_1"), each = 3),
d13C = c(-24, -25, -24.5, -12, -11.5, -12.2, -18, -18.2, -17.9),
d15N = c(5, 5.5, 5.2, 12, 11.8, 12.1, 8.5, 8.7, 8.4)
)
# Run MixSIAR test chain (1,000 iterations)
try({
res <- unmix_mixsiar(
data = raw_data,
tracers = c("d13C", "d15N"),
run = "test"
)
# Plot posterior proportions
plot_apportionment(res$apportionment, title = "MixSIAR Apportionment")
}, silent = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.