unmix_mixsiar: Bayesian Source Apportionment using MixSIAR

View source: R/unmix_mixsiar.R

unmix_mixsiarR Documentation

Bayesian Source Apportionment using MixSIAR

Description

A wrapper function that seamlessly formats an OceanTracer dataset (raw or averaged) and passes it to the MixSIAR Bayesian unmixing engine.

Usage

unmix_mixsiar(
  data,
  tracers = NULL,
  prior_type = "uninformative",
  prior_values = NULL,
  run = "normal",
  process_err = FALSE,
  resid_err = TRUE
)

Arguments

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 NULL (auto-detected).

prior_type

Character. "uninformative" (default, alpha=1) or "informative".

prior_values

Numeric vector. Required if prior_type = "informative". Must match the number of sources.

run

Character. MCMC run length. Options: "test", "very short", "short", "normal" (default), "long", "very long", "extreme".

process_err

Logical. Include process error in the JAGS model? Default FALSE.

resid_err

Logical. Include residual error in the JAGS model? Default TRUE.

Value

A named list containing:

apportionment

A data frame with posterior draw proportions for each source, formatted for plot_apportionment.

bayesian_summary

A data frame summarizing MCMC parameter posteriors (mean, SD, quantiles, Rhat).

jags_model

The raw rjags output object returned by MixSIAR.

Examples


# 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)
}



OceanTracer documentation built on Oct. 15, 2026, 5:09 p.m.