Here we step through the Lake Example using the script version of MixSIAR. For a demonstration using the GUI version, see the MixSIAR Manual. For a thorough walkthrough of how to use MixSIAR in a script, see the Wolves Example, which provides more commentary and explanation.
For a clean, runnable
.R script, look at
mixsiar_script_lake.R in the
example_scripts folder of the MixSIAR package install:
You can run the lake example script directly with:
The Lake Example data is simulated based on Francis et al. 2011 and we include it as a example of how MixSIAR can include a continuous effect. Here we examine the diet of zooplankton in 21 lakes using:
MixSIAR fits a continuous covariate as a linear regression in ILR/transform-space. Two terms are fit for the proportion of each source: an intercept and a slope. The plot uses the posterior median estimates of the intercept and slope, and the lines are curved because of the ILR-transform back into p-space. For details, or if you would like to make modifications, see ?plot_continous_var.R.
Fitting a model with a continuous effect is more complex than the categorical fixed/random effects and can be a bit finicky.
See ?load_mix_data for details.
The lake consumer data has 1 covariate, which we fit as a continuous effect (
cont_effects="Secchi.Mixed"). There are no fixed/random effects (
See ?load_source_data for details.
We have no fixed/random effects in the model (
source_factors=NULL), and we do not have concentration dependence data (
conc_dep=FALSE). We have the original “raw” source data, not means and SDs (
See ?load_discr_data for details.
This is your chance to check:
Calculate normalized surface area of the convex hull polygon(s) as in Brett (2014).
Note 1: discrimination SD is added to the source SD (see ?calc_area for details)
# Calculate the convex hull area, standardized by source variance calc_area(source=source,mix=mix,discr=discr)
##  3.053018
Define your prior, and then plot using “plot_prior”
In the Lake Example we demo the “Residual only” error option. The differences between “Residual * Process”, “Residual only”, and “Process only” are explained in Stock and Semmens (2016).
Choose one of the MCMC run options:
|run ==||Chain Length||Burn-in||Thin||# Chains|
run = "test" to check if 1) the data are loaded correctly and 2) the model is specified correctly:
After a test run works, increase the MCMC run to a value that may converge:
MixSIAR fits a continuous covariate as a linear regression in ILR/transform-space. Two terms are fit for the proportion of each source: an intercept and a slope. The plot uses the posterior median estimates of the intercept and slope, and the lines are curved because of the ILR-transform back into p-space. For details, or if you would like to make modifications, see ?plot_continous_var. See ?output_JAGS for output options.
The other posterior plots MixSIAR produces for a continuous effect show the estimated diet for the minimum, median, and maximum individuals.