simmr
Use:
install.packages('simmr')
then
library(simmr)
Some geese isotope data is included with this package. Find where it is with:
system.file("extdata", "geese_data.xls", package = "simmr")
Load into R with:
library(readxl)
= system.file("extdata", "geese_data.xls", package = "simmr")
path = lapply(excel_sheets(path), read_excel, path = path) geese_data
If you want to see what the original Excel sheet looks like you can run system(paste('open',path))
.
We can now separate out the data into parts
= geese_data[[1]]
targets = geese_data[[2]]
sources = geese_data[[3]]
TEFs = geese_data[[4]] concdep
simmr
= simmr_load(mixtures = as.matrix(targets[, 1:2]),
geese_simmr source_names = sources$Sources,
source_means = as.matrix(sources[,2:3]),
source_sds = as.matrix(sources[,4:5]),
correction_means = as.matrix(TEFs[,2:3]),
correction_sds = as.matrix(TEFs[,4:5]),
concentration_means = as.matrix(concdep[,2:3]),
group = as.factor(paste('Day', targets$Time)))
plot(geese_simmr, group = 1:8)
simmr
and check convergence= simmr_mcmc(geese_simmr)
geese_simmr_out summary(geese_simmr_out, type = 'diagnostics',
group = 1)
Check that the model fitted well:
posterior_predictive(geese_simmr_out, group = 5)
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 40
## Unobserved stochastic nodes: 46
## Total graph size: 190
##
## Initializing model
Look at the influence of the prior:
prior_viz(geese_simmr_out)
Look at the histogram of the dietary proportions:
plot(geese_simmr_out, type = 'histogram')
compare_groups(geese_simmr_out, groups = 1:4,
source_name = 'Enteromorpha')
## Most popular orderings are as follows:
## Probability
## Day 428 > Day 124 > Day 398 > Day 1 0.2053
## Day 428 > Day 398 > Day 124 > Day 1 0.1808
## Day 428 > Day 124 > Day 1 > Day 398 0.1614
## Day 428 > Day 398 > Day 1 > Day 124 0.1250
## Day 428 > Day 1 > Day 124 > Day 398 0.0861
## Day 428 > Day 1 > Day 398 > Day 124 0.0669
## Day 124 > Day 428 > Day 398 > Day 1 0.0417
## Day 124 > Day 428 > Day 1 > Day 398 0.0336
## Day 398 > Day 428 > Day 124 > Day 1 0.0317
## Day 398 > Day 428 > Day 1 > Day 124 0.0203
## Day 398 > Day 124 > Day 428 > Day 1 0.0086
## Day 124 > Day 398 > Day 428 > Day 1 0.0083
## Day 1 > Day 428 > Day 124 > Day 398 0.0050
## Day 124 > Day 1 > Day 428 > Day 398 0.0042
## Day 1 > Day 428 > Day 398 > Day 124 0.0033
## Day 124 > Day 1 > Day 398 > Day 428 0.0031
## Day 1 > Day 124 > Day 428 > Day 398 0.0028
## Day 398 > Day 1 > Day 124 > Day 428 0.0025
## Day 398 > Day 1 > Day 428 > Day 124 0.0025
## Day 124 > Day 398 > Day 1 > Day 428 0.0022
## Day 1 > Day 398 > Day 428 > Day 124 0.0017
## Day 1 > Day 398 > Day 124 > Day 428 0.0011
## Day 398 > Day 124 > Day 1 > Day 428 0.0011
## Day 1 > Day 124 > Day 398 > Day 428 0.0008
For the many more options available to run and analyse output, see the main vignette via vignette('simmr')