Title: | Fast Fitting of Stable Isotope Mixing Models with Covariates |
---|---|
Description: | Fast fitting of Stable Isotope Mixing Models in R. Allows for the inclusion of covariates. Also has built-in summary functions and plot functions which allow for the creation of isospace plots. Variational Bayes is used to fit these models, methods as described in: Tran et al., (2021) <doi:10.48550/arXiv.2103.01327>. |
Authors: | Emma Govan [cre, aut], Andrew Parnell [aut], Ahmed Shalaby [ctb], Alan Inglis [ctb] |
Maintainer: | Emma Govan <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.12 |
Built: | 2024-11-28 06:33:21 UTC |
Source: | CRAN |
Dataset from Nifong et al 2015 which contains 2 food sources, 181 individuals and 2 isotopes. This dataset includes multiple covariates as well as TDF means and sds.
alligator_data
alligator_data
A list with the following elements
A two column matrix containing delta 13C and delta 15N values respectively
A character vector of unique ID values
A character vector of tag ID
A numeric vector of latitude
A numeric vector of longitude
A character vector of date
A numeric vector of year
A character vector of habitat
A character vector of sex
A numeric vector of length in cm
A character vector of size class
A character vector for sex times size class
A character vector of source names
A data frame of source means for same tracers as in Mixtures
A data frame of standard deviations of sources for same tracers as in Mixtures
A numeric vector of number of sources
A data frame of means for TEFs for same tracers as in Mixtures
A data frame of sds for TEFs for same tracers as in Mixtures
<doi:10.1111/1365-2656.12306>
Cladocera data from Galloway et al 2015. This dataset has 14 individuals on 7 food sources and 22 tracers. The id column can be used as a covariate. This dataset includes TDFs.
cladocera_data
cladocera_data
A list with the following elements
numeric vector of ID number
character vector of group ID
Data frame of tracer values. There are 22 fatty acids as tracers in this dataset.
character vector of tracer names
data frame of tracer means for each of the 7 food sources
data frame of tracer sds for each of the 7 food sources
numeric vector of the number of each food source collected
data frame with TDF means for each food source on each tracer
data frame with TDF sds for each food source on each tracer
<doi:10.1111/fwb.12394>
cosimmr is a package that has been developed to allow for running of Stable Isotope Mixing Models in R. It allows for the inclusion of covariates and has been designed to be easy to use for non-expert users. cosimmr uses Fixed Form Variational Bayes to run SIMMs, instead of MCMC. This allows for faster running of models without any issues with convergence
Emma Govan <[email protected]>, Andrew Parnell
cosimmr_input
object through the Fixed Form Variational
Bayes(FFVB) functionThis is the main function of cosimmr. It takes a cosimmr_input
object
created via cosimmr_load
, runs it in fixed form
Variational Bayes to determine the dietary proportions, and then
outputs a cosimmr_output
object for further analysis and plotting
via plot.cosimmr_output
.
cosimmr_ffvb( cosimmr_in, prior_control = list(mu_0 = rep(0, (cosimmr_in$n_sources * cosimmr_in$n_covariates)), mu_log_sig_sq_0 = rep(0, cosimmr_in$n_tracers), sigma_0 = 1, tau_shape = rep(1, cosimmr_in$n_tracers), tau_rate = rep(1, cosimmr_in$n_tracers)), ffvb_control = list(n_output = 3600, S = 500, P = 50, beta_1 = 0.75, beta_2 = 0.75, tau = 500, eps_0 = 0.0011, t_W = 500) )
cosimmr_ffvb( cosimmr_in, prior_control = list(mu_0 = rep(0, (cosimmr_in$n_sources * cosimmr_in$n_covariates)), mu_log_sig_sq_0 = rep(0, cosimmr_in$n_tracers), sigma_0 = 1, tau_shape = rep(1, cosimmr_in$n_tracers), tau_rate = rep(1, cosimmr_in$n_tracers)), ffvb_control = list(n_output = 3600, S = 500, P = 50, beta_1 = 0.75, beta_2 = 0.75, tau = 500, eps_0 = 0.0011, t_W = 500) )
cosimmr_in |
An object created via the function |
prior_control |
A list of values including arguments named |
ffvb_control |
A list of values including arguments named |
An object of class cosimmr_output
with two named top-level
components:
input |
The |
output |
A set of outputs produced by
the FFVB function. These can be analysed using the
|
Emma Govan <[email protected]>, Andrew Parnell
Andrew C. Parnell, Donald L. Phillips, Stuart Bearhop, Brice X. Semmens, Eric J. Ward, Jonathan W. Moore, Andrew L. Jackson, Jonathan Grey, David J. Kelly, and Richard Inger. Bayesian stable isotope mixing models. Environmetrics, 24(6):387–399, 2013.
Andrew C Parnell, Richard Inger, Stuart Bearhop, and Andrew L Jackson. Source partitioning using stable isotopes: coping with too much variation. PLoS ONE, 5(3):5, 2010.
cosimmr_load
for creating objects suitable for this
function, plot.cosimmr_input
for creating isospace plots,
summary.cosimmr_output
for summarising output, and
plot.cosimmr_output
for plotting output.
## See the package vignette for a detailed run through of these examples # Data set 1: 10 obs on 2 isos, 4 sources, with tefs and concdep data(geese_data_day1) x = c(1,2,3,2,1,3,2,1,2) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ x, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Print it print(cosimmr_1_out) # Summary summary(cosimmr_1_out, type = "correlations") summary(cosimmr_1_out, type = "statistics") ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics")) # Plot plot(cosimmr_1_out, type = "beta_boxplot", cov_name = "x") plot(cosimmr_1_out, type = "beta_histogram", cov_name = "x")
## See the package vignette for a detailed run through of these examples # Data set 1: 10 obs on 2 isos, 4 sources, with tefs and concdep data(geese_data_day1) x = c(1,2,3,2,1,3,2,1,2) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ x, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Print it print(cosimmr_1_out) # Summary summary(cosimmr_1_out, type = "correlations") summary(cosimmr_1_out, type = "statistics") ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics")) # Plot plot(cosimmr_1_out, type = "beta_boxplot", cov_name = "x") plot(cosimmr_1_out, type = "beta_histogram", cov_name = "x")
This function takes in the mixture data, food source means and standard
deviations, and (optionally) correction factor means and standard
deviations, and concentration proportions. It performs some (non-exhaustive)
checking of the data to make sure it will run through simmr. It outputs an
object of class cosimmr_input
.
cosimmr_load( formula, source_names, source_means, source_sds, correction_means = NULL, correction_sds = NULL, concentration_means = NULL, scale_x = TRUE )
cosimmr_load( formula, source_names, source_means, source_sds, correction_means = NULL, correction_sds = NULL, concentration_means = NULL, scale_x = TRUE )
formula |
Formula giving in form y ~ x where y is a vector or matrix of mixture values and x is a vector or matrix of covariates |
source_names |
The names of the sources given as a character string |
source_means |
The means of the source values, given as a matrix where the number of rows is the number of sources and the number of columns is the number of tracers |
source_sds |
The standard deviations of the source values, given as a matrix where the number of rows is the number of sources and the number of columns is the number of tracers |
correction_means |
The means of the correction values, given as a matrix where the number of rows is the number of sources and the number of columns is the number of tracers. If not provided these are set to 0. |
correction_sds |
The standard deviations of the correction values, given as a matrix where the number of rows is the number of sources and the number of columns is the number of tracers. If not provided these are set to 0. |
concentration_means |
The means of the concentration values, given as a matrix where the number of rows is the number of sources and the number of columns is the number of tracers. These should be between 0 and 1. If not provided these are all set to 1. |
scale_x |
Whether or not you wish to scale the x values provided, or run the model using the original x values. Defaults to TRUE. |
For standard stable isotope mixture modelling, the mixture matrix will
contain a row for each individual and a column for each isotopic value.
cosimmr
will allow for any number of isotopes and any number of
observations, within computational limits. The source means/sds should be
provided for each food source on each isotope. The correction means (usually
trophic enrichment factors) can be set as zero if required, and should be of
the same shape as the source values. The concentration dependence means
should be estimated values of the proportion of each element in the food
source in question and should be given in proportion format between 0 and 1.
At present there is no means to include concentration standard deviations.
An object of class cosimmr_input
with the following elements:
mixtures |
The mixture data |
source_names |
Source means |
sources_sds |
Source standard deviations |
correction_means |
Correction means |
correction_sds |
Correction standard deviations |
concentration_means |
Concentration dependence means |
n_obs |
The number of observations |
n_tracers |
The number of tracers/isotopes |
n_sources |
The number of sources |
n_groups |
The number of groups |
Emma Govan <[email protected]>, Andrew Parnell
See cosimmr_ffvb
for complete examples.
# A simple example with 10 observations, 2 tracers and 4 sources data(geese_data_day1) simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means, scale_x = TRUE ) ) print(simmr_1)
# A simple example with 10 observations, 2 tracers and 4 sources data(geese_data_day1) simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means, scale_x = TRUE ) ) print(simmr_1)
A real Geese data set with 251 observations on 2 isotopes, with 4 sources, and with corrections/trophic enrichment factors (TEFs or TDFs), and concentration dependence means. Taken from Inger et al (2016). See link for paper
geese_data
geese_data
A list with the following elements
A two column matrix containing delta 13C and delta 15N values respectively
A character vector of the food source names
A character vector of the tracer names (d13C, d15N, d34S)
A matrix of source mean values for the tracers in the same order as mixtures
above
A matrix of source sd values for the tracers in the same order as mixtures
above
A matrix of TEFs mean values for the tracers in the same order as mixtures
above
A matrix of TEFs sd values for the tracers in the same order as mixtures
above
A matrix of concentration dependence mean values for the tracers in the same order as mixtures
above
<doi:10.1111/j.1365-2656.2006.01142.x>
A real Geese data set with 9 observations on 2 isotopes, with 4 sources, and with corrections/trophic enrichment factors (TEFs or TDFs), and concentration dependence means. Taken from Inger et al (2016). See link for paper
geese_data_day1
geese_data_day1
A list with the following elements
A two column matrix containing delta 13C and delta 15N values respectively
A character vector of the food source names
A character vector of the tracer names (d13C, d15N, d34S)
A matrix of source mean values for the tracers in the same order as mixtures
above
A matrix of source sd values for the tracers in the same order as mixtures
above
A matrix of TEFs mean values for the tracers in the same order as mixtures
above
A matrix of TEFs sd values for the tracers in the same order as mixtures
above
A matrix of concentration dependence mean values for the tracers in the same order as mixtures
above
...
<doi:10.1111/j.1365-2656.2006.01142.x>
Isopod data from Galloway et al 2014. This dataset has 8 tracers (fatty acids), 30 individuals and 3 food sources. This dataset includes TDFs.
iso_data
iso_data
A list with the following elements
A character vector with name of site for each individual
Data frame with 8 tracer values for 30 individuals
character vector of tracer names
character vector of food source names
Data frame of source means with values for each food source on each tracer
Data frame of source sds with values for each food source on each tracer
numeric vector of number of each source obtained
Data frame of TDF means for each food source on each tracer
Data frame of TDF sds for each food source on each tracer
<doi:10.3354/meps10860>
cosimmr_input
data created from cosimmr_load
This function creates iso-space (AKA tracer-space or delta-space) plots. They are vital in determining whether the data are suitable for running in a SIMM.
## S3 method for class 'cosimmr_input' plot( x, tracers = c(1, 2), title = "Tracers plot", xlab = colnames(x$mixtures)[tracers[1]], ylab = colnames(x$mixtures)[tracers[2]], sigmas = 1, mix_name = "Mixtures", colour = TRUE, colour_by_cov = FALSE, cov_name = NULL, ggargs = NULL, ... )
## S3 method for class 'cosimmr_input' plot( x, tracers = c(1, 2), title = "Tracers plot", xlab = colnames(x$mixtures)[tracers[1]], ylab = colnames(x$mixtures)[tracers[2]], sigmas = 1, mix_name = "Mixtures", colour = TRUE, colour_by_cov = FALSE, cov_name = NULL, ggargs = NULL, ... )
x |
An object created via the function |
tracers |
The choice of tracers to plot. If there are more than two tracers, it is recommended to plot every pair of tracers to determine whether the mixtures lie in the mixing polygon defined by the sources |
title |
A title for the graph |
xlab |
The x-axis label. By default this is assumed to be delta-13C but can be made richer if required. See examples below. |
ylab |
The y-axis label. By default this is assumed to be delta-15N in per mil but can be changed as with the x-axis label |
sigmas |
The number of standard deviations to plot on the source values. Defaults to 1. |
mix_name |
A optional string containing the name of the mixture objects, e.g. Geese. |
colour |
If TRUE (default) creates a plot. If not, puts the plot in black and white |
colour_by_cov |
if TRUE this allows users to colour the mixtures on the isospace plot by a specified covariate. Defaults to FALSE |
cov_name |
The name of the covariate the user wishes to colour the mixture points on the plot by |
ggargs |
Extra arguments to be included in the ggplot (e.g. axis limits) |
... |
Not used |
It is desirable to have the vast majority of the mixture observations to be inside the convex hull defined by the food sources. When there are more than two tracers (as in one of the examples below) it is recommended to plot all the different pairs of the food sources. See the vignette for further details of richer plots.
isospace plot
Emma Govan <[email protected]>, Andrew Parnell
See plot.cosimmr_output
for plotting the output of a
simmr run. See cosimmr_ffvb
for running a cosimmr object once the
iso-space is deemed acceptable.
# A simple example with 10 observations, 4 food sources and 2 tracers data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,2,3,1,2,3,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) ### A more complicated example with 30 obs, 3 tracers and 4 sources data(simmr_data_2) cosimmr_3 <- with( simmr_data_2, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot 3 times - first default d13C vs d15N plot(cosimmr_3) # Now plot d15N vs d34S plot(cosimmr_3, tracers = c(2, 3)) # and finally d13C vs d34S plot(cosimmr_3, tracers = c(1, 3))
# A simple example with 10 observations, 4 food sources and 2 tracers data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,2,3,1,2,3,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) ### A more complicated example with 30 obs, 3 tracers and 4 sources data(simmr_data_2) cosimmr_3 <- with( simmr_data_2, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot 3 times - first default d13C vs d15N plot(cosimmr_3) # Now plot d15N vs d34S plot(cosimmr_3, tracers = c(2, 3)) # and finally d13C vs d34S plot(cosimmr_3, tracers = c(1, 3))
cosimmr_ffvb
.This function allows for 4 different types of plots of the simmr output
created from cosimmr_ffvb
. The
types are: plot of beta values
## S3 method for class 'cosimmr_output' plot( x, type = c("isospace", "beta_histogram", "beta_boxplot", "prop_histogram", "prop_density", "covariates_plot"), obs = 1, cov_name = NULL, binwidth = 0.05, alpha = 0.5, title = NULL, n_output = 3600, source = NULL, one_plot = FALSE, n_pred = 1000, ... )
## S3 method for class 'cosimmr_output' plot( x, type = c("isospace", "beta_histogram", "beta_boxplot", "prop_histogram", "prop_density", "covariates_plot"), obs = 1, cov_name = NULL, binwidth = 0.05, alpha = 0.5, title = NULL, n_output = 3600, source = NULL, one_plot = FALSE, n_pred = 1000, ... )
x |
An object of class |
type |
The type of plot required. Can be one or more of 'isospace', 'beta_histogram', 'beta_boxplot', 'prob_histogram', 'prob_density', 'covariates_plot' |
obs |
The observation number you wish to plot |
cov_name |
The name of the covariate you wish to plot (for beta and covariates plot) |
binwidth |
The width of the bins for the histogram. Defaults to 0.05 |
alpha |
The degree of transparency of the plots. Not relevant for matrix plots |
title |
The title of the plot. |
n_output |
The number of theta samples you wish to plot with. Defaults to 3600 |
source |
The number or name of the source you wish to plot over for 'covariates_plot', defaults to NULL which means all sources are used |
one_plot |
Whether to plot line covariates plot on one plot. Defaults to FALSE |
n_pred |
Number of points to use when plotting line covariates plot. Defaults to 1000. |
... |
Currently not used |
The matrix plot should form a necessary part of any SIMM analysis since it allows the user to judge which sources are identifiable by the model. Further detail about these plots is provided in the vignette.
one or more of 'isospace', 'beta_histogram', 'beta_boxplot', 'prop_histogram', 'prop_density', or 'covariates_plot'
Emma Govan <[email protected]>, Andrew Parnell
See cosimmr_ffvb
for
creating objects suitable for this function, and many more examples. See
also cosimmr_load
for creating simmr objects,
plot.cosimmr_input
for creating isospace plots.
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) # Load into simmr simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(simmr_1) # FFVB run simmr_1_out <- cosimmr_ffvb(simmr_1) plot(simmr_1_out, type = c("isospace", "beta_hist"))
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) # Load into simmr simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(simmr_1) # FFVB run simmr_1_out <- cosimmr_ffvb(simmr_1) plot(simmr_1_out, type = c("isospace", "beta_hist"))
cosimmr_ffvb
.This function allows for 4 different types of plots of the simmr output
created from cosimmr_ffvb
. The
types are: plot of beta values
## S3 method for class 'cosimmr_pred_out' plot( x, type = c("beta_histogram", "beta_boxplot", "prop_obs", "prop_density"), obs = 1, cov_name = NULL, binwidth = 0.05, alpha = 0.5, title = NULL, n_output = 3600, ... )
## S3 method for class 'cosimmr_pred_out' plot( x, type = c("beta_histogram", "beta_boxplot", "prop_obs", "prop_density"), obs = 1, cov_name = NULL, binwidth = 0.05, alpha = 0.5, title = NULL, n_output = 3600, ... )
x |
An object of class |
type |
The type of plot required. Can be one or more of 'isospace', 'beta_histogram', 'beta_boxplot', 'prob_histogram', 'prob_density', 'covariates_plot' |
obs |
The observation you wish to plot |
cov_name |
The name of the covariate you wish to plot (for beta and covariate plots) |
binwidth |
The width of the bins for the histogram. Defaults to 0.05 |
alpha |
The degree of transparency of the plots. Not relevant for matrix plots |
title |
The title of the plot. |
n_output |
The number of theta samples you wish to plot with. Defaults to 3600 |
... |
Currently not used |
The matrix plot should form a necessary part of any SIMM analysis since it allows the user to judge which sources are identifiable by the model. Further detail about these plots is provided in the vignette.
one or more of 'isospace', 'beta_histogram', 'beta_boxplot', 'prop_histogram', 'prop_density', or 'covariates_plot'
Emma Govan <[email protected]>>, Andrew Parnell
See cosimmr_ffvb
for
creating objects suitable for this function, and many more examples. See
also cosimmr_load
for creating simmr objects,
plot.cosimmr_input
for creating isospace plots.
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) # Load into simmr cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) plot(cosimmr_1_out, type = c("isospace", "beta_hist"))
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) # Load into simmr cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) plot(cosimmr_1_out, type = c("isospace", "beta_hist"))
This function takes the output from cosimmr_ffvb
and plots
the posterior predictive distribution to enable visualisation of model fit.
The simulated posterior predicted values are returned as part of the object
and can be saved for external use
posterior_predictive( cosimmr_out, prob = 0.5, plot_ppc = TRUE, n_samples = 3600, sort_data = TRUE )
posterior_predictive( cosimmr_out, prob = 0.5, plot_ppc = TRUE, n_samples = 3600, sort_data = TRUE )
cosimmr_out |
A run of the cosimmr model from |
prob |
The probability interval for the posterior predictives. The default is 0.5 (i.e. 50pc intervals) |
plot_ppc |
Whether to create a bayesplot of the posterior predictive or not. |
n_samples |
The number of samples you wish to generate for y_pred. Defaults to 3600. |
sort_data |
Whether to order the data from lowest to highest predicted mean or not. Defaults to TRUE. |
plot of posterior predictives and simulated values
#' @author Emma Govan <[email protected]> Andrew Parnell
cosimmr_ffvb
for creating objects suitable for this
function
data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,2,1,2,3,2,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Prior predictive post_pred <- posterior_predictive(cosimmr_1_out)
data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,2,1,2,3,2,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Prior predictive post_pred <- posterior_predictive(cosimmr_1_out)
Predicts proportion of each source in a mixture, based on values provided for covariates
## S3 method for class 'cosimmr_output' predict(object, x_pred, n_output = 3600, ...)
## S3 method for class 'cosimmr_output' predict(object, x_pred, n_output = 3600, ...)
object |
An object of class |
x_pred |
A data.frame of covariate values that the user wishes to predict source proportions for, provided in the same order that the original covariance matrix was. Important for this to be a data.frame otherwise numeric values can be set as characters and this causes incorrect calculations. |
n_output |
the number of posterior samples to generate. Defaults to 3600. |
... |
Other arguments (not used) |
object of class 'cosimmr_pred_out'
Emma Govan <[email protected]> Andrew Parnell
Andrew C. Parnell, Donald L. Phillips, Stuart Bearhop, Brice X. Semmens, Eric J. Ward, Jonathan W. Moore, Andrew L. Jackson, Jonathan Grey, David J. Kelly, and Richard Inger. Bayesian stable isotope mixing models. Environmetrics, 24(6):387–399, 2013.
cosimmr_load
for creating objects suitable for this
function, and
plot.cosimmr_output
for plotting output.
## See the package vignette for a detailed run through of these 4 examples # Data set 1: 10 obs on 2 isos, 4 sources, with tefs and concdep data(geese_data_day1) cov_1 = c(1,2,3,2,3,1,1,1,2) simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ cov_1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(simmr_1) # Print simmr_1 # FFVB run simmr_1_out <- cosimmr_ffvb(simmr_1) # Print it print(simmr_1_out) # Plot plot(simmr_1_out, type = "isospace") plot(simmr_1_out, type = "beta_histogram", cov_name = "cov_1") x_pred = data.frame(cov_1 = c(1,5)) pred_array<-predict(simmr_1_out, x_pred)
## See the package vignette for a detailed run through of these 4 examples # Data set 1: 10 obs on 2 isos, 4 sources, with tefs and concdep data(geese_data_day1) cov_1 = c(1,2,3,2,3,1,1,1,2) simmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ cov_1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(simmr_1) # Print simmr_1 # FFVB run simmr_1_out <- cosimmr_ffvb(simmr_1) # Print it print(simmr_1_out) # Plot plot(simmr_1_out, type = "isospace") plot(simmr_1_out, type = "beta_histogram", cov_name = "cov_1") x_pred = data.frame(cov_1 = c(1,5)) pred_array<-predict(simmr_1_out, x_pred)
Print simmr input object
## S3 method for class 'cosimmr_input' print(x, ...)
## S3 method for class 'cosimmr_input' print(x, ...)
x |
An object of class |
... |
Other arguments (not supported) #' @author Emma Govan <[email protected]> Andrew Parnell |
A neat presentation of your simmr object.
cosimmr_load
for creating objects suitable for this
function
Print a simmr output object
## S3 method for class 'cosimmr_output' print(x, ...)
## S3 method for class 'cosimmr_output' print(x, ...)
x |
An object of class |
... |
Other arguments (not supported) |
Returns a neat summary of the object
cosimmr_ffvb
for creating
cosimmr_output
objects
This function takes the output from cosimmr_ffvb
and plots the
prior distribution to enable visual
inspection. This can be used by itself or together with
posterior_predictive
to visually evaluate the influence of
the prior on the posterior distribution.
prior_viz( cosimmr_out, plot = TRUE, include_posterior = TRUE, n_sims = 10000, scales = "free" )
prior_viz( cosimmr_out, plot = TRUE, include_posterior = TRUE, n_sims = 10000, scales = "free" )
cosimmr_out |
A run of the cosimmr model from |
plot |
Whether to create a density plot of the prior or not. The simulated prior values are returned as part of the object |
include_posterior |
Whether to include the posterior distribution on top of the priors. Defaults to TRUE. The posterior returned is of the mean value of covariates |
n_sims |
The number of simulations from the prior distribution |
scales |
The type of scale from |
A list containing plot
: the ggplot object (useful if requires customisation), and sim
: the simulated prior values which can be compared with the posterior densities
#' @author Emma Govan <[email protected]> Andrew Parnell
cosimmr_ffvb
for creating objects suitable for this
function
data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Prior predictive prior <- prior_viz(cosimmr_1_out) head(prior$p_prior_sim) summary(prior$p_prior_sim)
data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # Print cosimmr_1 # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Prior predictive prior <- prior_viz(cosimmr_1_out) head(prior$p_prior_sim) summary(prior$p_prior_sim)
A simple fake data set with 10 observations on 2 isotopes, with 4 sources, and with corrections/trophic enrichment factors (TEFs or TDFs), and concentration dependence means
simmr_data_1
simmr_data_1
A list with the following elements
A two column matrix containing delta 13C and delta 15N values respectively
A character vector of the food source names
A character vector of the tracer names (d13C and d15N)
A matrix of source mean values for the tracers in the same order as mixtures
above
A matrix of source sd values for the tracers in the same order as mixtures
above
A matrix of TEFs mean values for the tracers in the same order as mixtures
above
A matrix of TEFs sd values for the tracers in the same order as mixtures
above
A matrix of concentration dependence mean values for the tracers in the same order as mixtures
above
A fake data set with 30 observations on 3 isotopes, with 4 sources, and with corrections/trophic enrichment factors (TEFs or TDFs), and concentration dependence means
simmr_data_2
simmr_data_2
A list with the following elements
A three column matrix containing delta 13C, delta 15N, and delta 34S values respectively
A character vector of the food source names
A character vector of the tracer names (d13C, d15N, d34S)
A matrix of source mean values for the tracers in the same order as mixtures
above
A matrix of source sd values for the tracers in the same order as mixtures
above
A matrix of TEFs mean values for the tracers in the same order as mixtures
above
A matrix of TEFs sd values for the tracers in the same order as mixtures
above
A matrix of concentration dependence mean values for the tracers in the same order as mixtures
above
A fake box data set identified by Fry (2014) as a failing of SIMMs See the link for more interpretation of these data and the output
square_data
square_data
A list with the following elements
A two column matrix containing delta 13C and delta 15N values respectively
A character vector of the food source names
A character vector of the tracer names (d13C, d15N)
A matrix of source mean values for the tracers in the same order as mixtures
above
A matrix of source sd values for the tracers in the same order as mixtures
above
A matrix of TEFs mean values for the tracers in the same order as mixtures
above
A matrix of TEFs sd values for the tracers in the same order as mixtures
above
A matrix of concentration dependence mean values for the tracers in the same order as mixtures
above
<doi:10.3354/meps10535>
cosimmr_ffvb
Produces textual summaries and convergence diagnostics for an object created
with cosimmr_ffvb
. The different
options are: 'quantiles' which produces credible intervals
for the parameters, 'statistics' which produces means and standard
deviations, and 'correlations' which produces correlations between the
parameters.
## S3 method for class 'cosimmr_output' summary( object, type = c("quantiles", "statistics", "correlations"), obs = 1, ... )
## S3 method for class 'cosimmr_output' summary( object, type = c("quantiles", "statistics", "correlations"), obs = 1, ... )
object |
An object of class |
type |
The type of output required. At least none of quantiles', 'statistics', or 'correlations'. |
obs |
The observation to generate a summary for. Defaults to 1. |
... |
Not used |
The quantile output allows easy calculation of 95 per cent credible intervals of the posterior dietary proportions. The correlations allow the user to judge which sources are non-identifiable.
A list containing the following components:
quantiles |
The quantiles of each parameter from the posterior distribution |
statistics |
The means and standard deviations of each parameter |
correlations |
The posterior correlations between the parameters |
Note that this object is reported silently so will be discarded unless the function is called with an object as in the example below.
Emma Govan <[email protected]> Andrew Parnell
See cosimmr_ffvb
for creating objects suitable for
this function, and many more examples.
See also cosimmr_load
for creating cosimmr objects,
plot.cosimmr_input
for creating isospace plots,
plot.cosimmr_output
for plotting output.
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Summarise summary(cosimmr_1_out) # This outputs all the summaries summary(cosimmr_1_out, type = "quantiles") # Just the diagnostics # Store the output in an ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics") )
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ 1, source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Summarise summary(cosimmr_1_out) # This outputs all the summaries summary(cosimmr_1_out, type = "quantiles") # Just the diagnostics # Store the output in an ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics") )
cosimmr_ffvb
Produces textual summaries and convergence diagnostics for an object created
with cosimmr_ffvb
. The different
options are: 'quantiles' which produces credible intervals
for the parameters, 'statistics' which produces means and standard
deviations, and 'correlations' which produces correlations between the
parameters.
## S3 method for class 'cosimmr_pred_out' summary( object, type = c("quantiles", "statistics", "correlations"), obs = 1, ... )
## S3 method for class 'cosimmr_pred_out' summary( object, type = c("quantiles", "statistics", "correlations"), obs = 1, ... )
object |
An object of class |
type |
The type of output required. At least none of quantiles', 'statistics', or 'correlations'. |
obs |
The observation to generate a summary for. Defaults to 1. |
... |
Not used |
The quantile output allows easy calculation of 95 per cent credible intervals of the posterior dietary proportions. The correlations allow the user to judge which sources are non-identifiable.
A list containing the following components:
quantiles |
The quantiles of each parameter from the posterior distribution |
statistics |
The means and standard deviations of each parameter |
correlations |
The posterior correlations between the parameters |
Note that this object is reported silently so will be discarded unless the function is called with an object as in the example below.
Emma Govan <[email protected]> Andrew Parnell
See cosimmr_ffvb
for creating objects suitable for
this function, and many more examples.
See also cosimmr_load
for creating cosimmr objects,
plot.cosimmr_input
for creating isospace plots,
plot.cosimmr_output
for plotting output.
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,3,2,3,1,2,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Summarise summary(cosimmr_1_out) # This outputs all the summaries summary(cosimmr_1_out, type = "quantiles") # Just the diagnostics # Store the output in ans ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics") )
# A simple example with 10 observations, 2 tracers and 4 sources # The data data(geese_data_day1) cosimmr_1 <- with( geese_data_day1, cosimmr_load( formula = mixtures ~ c(1,2,3,3,2,3,1,2,1), source_names = source_names, source_means = source_means, source_sds = source_sds, correction_means = correction_means, correction_sds = correction_sds, concentration_means = concentration_means ) ) # Plot plot(cosimmr_1) # FFVB run cosimmr_1_out <- cosimmr_ffvb(cosimmr_1) # Summarise summary(cosimmr_1_out) # This outputs all the summaries summary(cosimmr_1_out, type = "quantiles") # Just the diagnostics # Store the output in ans ans <- summary(cosimmr_1_out, type = c("quantiles", "statistics") )