Title: | Bayesian trophic position models using stan |
---|---|
Description: | Bayesian trophic position models using stan by leveraging 'brms' for stable isotope data. Trophic position models are derived by using equations from Post (2002) <doi:10.1890/0012-9658(2002)083[0703:USITET]2.0.CO;2>, and Huevel et al. (2024) <doi:10.1139/cjfas-2024-0028>. |
Authors: | Benjamin L. Hlina [aut, cre] |
Maintainer: | Benjamin L. Hlina <[email protected]> |
License: | CC0 |
Version: | 0.1.0 |
Built: | 2025-03-15 02:24:47 UTC |
Source: | https://github.com/benjaminhlina/trps |
Calculate for a two source trophic position model using
equations from Post 2002.
add_alpha(data, abs = FALSE)
add_alpha(data, abs = FALSE)
data |
|
abs |
logical that controls whether the absolute value is taken for the
numerator and denominator. Default is |
where is the isotopic value for consumer,
is the mean isotopic value for baseline 1 and
is the mean isotopic value for baseline 2.
a data.frame
that has alpha
, min_alpha
, and max_alpha
added.
combined_iso |> add_alpha()
combined_iso |> add_alpha()
Stable isotope data (C and
N) for amphipods collected from an ecoregion in
Lake Ontario.
baseline_1_iso
baseline_1_iso
data.frame
containing 14 rows and 5 variables
name of the spcies (i.e., Amphipoda)
ecoregion where samples were collected
observed values for C
observed values for N
Stable isotope data (C and
N) for dreissenid collected from an ecoregion in
Lake Ontario.
baseline_2_iso
baseline_2_iso
data.frame
containing 12 rows and 5 variables
name of the spcies (i.e., Dreissenids)
ecoregion where samples were collected
observed values for C
observed values for N
Stable isotope data (C and
N) for lake trout collected from two ecoregions in
Lake Ontario. Values of
C and
N for a benthic baseline (amphipods; baseline 1;
d13c_b1
and d15n_b1
) and pelagic baseline
(dreissenids; baseline 2; d13c_b2
and d15n_b2
) with the means for each
baseline calculated (c1
, n1
, c2
, and n2
).
combined_iso
combined_iso
data.frame
containing 117 rows and 13 variables
row id number
name of the spcies (i.e., Lake Trout)
ecoregion where samples were collected
observed values for C of consumer
observed values for N of consumer
observed values for C of baseline 1
observed values for N of baseline 1
observed values for C of baseline 2
observed values for N of baseline 2
mean values for C of baseline 1
mean values for N of baseline 1
mean values for C of baseline 2
mean values for N of baseline 2
Stable isotope data (C and
N) for lake trout collected from an ecoregion in
Lake Ontario.
consumer_iso
consumer_iso
data.frame
containing 30 rows and 6 variables
name of the spcies (i.e., Lake Trout)
ecoregion where samples were collected
observed values for C
observed values for N
Estimate trophic position using a one source model derived from Post 2002 using a Bayesian framework.
one_source_model(bp = FALSE)
one_source_model(bp = FALSE)
bp |
logical value that controls whether informed priors are
supplied to the model for |
N are values from the consumer,
is mean
N values of baseline 1,
N is the trophic discrimination factor for N (i.e.,
dn
mean
of 3.4
), is trophic position, and
is the
trophic level of baselines which are often a primary consumer (e.g.,
2
).
The data supplied to brms()
needs to have the following variables d15n
,
n1
, and l1
() which is usually
2
.
returns model structure for one source model to be used in a
brms()
call.
one_source_model()
one_source_model()
Create priors for one source trophic position model derived from Post 2002.
one_source_priors(bp = FALSE)
one_source_priors(bp = FALSE)
bp |
logical value that controls whether informed priors are
supplied to the model for |
returns priors for one source model to be used in a brms()
call.
one_source_priors()
one_source_priors()
Adjust priors for one source trophic position model derived from Post 2002.
one_source_priors_params( n1 = NULL, n1_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
one_source_priors_params( n1 = NULL, n1_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
n1 |
mean ( |
n1_sigma |
variance ( |
dn |
mean ( |
dn_sigma |
variance ( |
tp_lb |
lower bound prior for trophic position. Defaults to |
tp_ub |
upper bound prior for trophic position. Defaults to |
sigma_lb |
lower bound prior for |
sigma_ub |
upper bound prior for |
bp |
logical value that controls whether informed priors are
supplied to the model for |
This function allows the user to adjust the priors for the following variables in the equation above:
The mean (n1
; ) and variance (
n1_sigma
; ) for
the mean
N for a given baseline (
).
This prior assumes a normal distribution.
The mean (dn
; ) and variance (
dn_sigma
; ) of
N (i.e, trophic enrichment
factor). This prior assumes a normal distribution.
The lower (tp_lb
) and upper (tp_ub
) bounds for trophic position.
This prior assumes a uniform distribution.
The lower (sigma_lb
) and upper (sigma_ub
) bounds for
variance (). This prior assumes a uniform distribution.
stanvars
object to be used with brms()
call.
one_source_priors()
, one_source_model()
, and brms::brms()
one_source_priors_params()
one_source_priors_params()
Trophic position using a two source model derived from Post 2002 using a Bayesian framework.
two_source_model(bp = FALSE, lambda = NULL)
two_source_model(bp = FALSE, lambda = NULL)
bp |
logical value that controls whether informed priors are
supplied to the model for both |
lambda |
numerical value, |
We will use the following equations from Post 2002:
For equation 1)
where is the isotopic value for consumer,
is the ratio between baselines and consumer
,
is the mean isotopic value for baseline 1, and
is the mean isotopic value for baseline 2
For equation 2) and 3)
N are values from the consumer,
is
N values of baseline 1,
is
N values of baseline 2,
N is the trophic discrimination factor for N (i.e., mean of
3.4
),
tp is trophic position, and and/or
are the trophic levels of
baselines which are often a primary consumer (e.g.,
2
or 2.5
).
The data supplied to brms()
when using baselines at the same trophic level
(lambda
argument set to 1
) needs to have the following variables, d15n
,
c1
, c2
, n1
, n2
, l1
() which is usually
2
.
If using baselines at different trophic levels (lambda
argument set to 2
)
the data frame needs to have l1
and l2
with a numerical value for
each trophic level (e.g.,2
and 2.5
; and
).
returns model structure for two source model to be used in a
brms()
call.
two_source_model()
two_source_model()
Estimate trophic position using a two source model with
derived from
Post 2002 and Heuvel et al. 2024 using a Bayesian framework.
two_source_model_ar(bp = FALSE, lambda = NULL)
two_source_model_ar(bp = FALSE, lambda = NULL)
bp |
logical value that controls whether informed priors are
supplied to the model for both |
lambda |
numerical value, |
We will use the following equations derived from Post 2002 and Heuvel et al. 2024:
For equation 1)
This equation is a carbon source mixing model with
is the isotopic value for consumer,
is the mean isotopic value for baseline 1 and
is the mean isotopic value for baseline 2. This
equation is added to the data frame using
add_alpha()
.
For equation 2)
is being corrected using equations in
Heuvel et al. 2024
with
being the corrected value (bound by 0 and 1),
is the minimum
value calculated
using
add_alpha()
and being the maximum
value calculated using
add_alpha()
.
For equation 3) and 4)
N are values from the consumer,
is
N values of baseline 1,
is
N values of baseline 2,
N is the trophic discrimination factor for N (i.e., mean of
3.4
),
tp is trophic position, and and/or
are the trophic levels of
baselines which are often a primary consumer (e.g.,
2
or 2.5
).
The data supplied to brms()
when using baselines at the same trophic level
(lambda
argument set to 1
) needs to have the following variables, d15n
,
n1
, n2
, l1
() which is usually
2
. If using baselines at
different trophic levels (lambda
argument set to 2
) the data frame needs
to have l1
and l2
with a numerical value for each trophic level (e.g.,
2
and 2.5
; and
).
returns model structure for two source model to be used in a
brms()
call.
two_source_model_ar()
two_source_model_ar()
and carbon mixing modelEstimate trophic position using a two source model with derived from
Post 2002 and Heuvel et al. 2024 using a Bayesian framework.
two_source_model_arc(bp = FALSE, lambda = NULL)
two_source_model_arc(bp = FALSE, lambda = NULL)
bp |
logical value that controls whether informed priors are
supplied to the model for both |
lambda |
numerical value, |
We will use the following equations derived from Post 2002 and Heuvel et al. 2024:
For equation 1)
This equation is a carbon source mixing model with
is the isotopic value for consumer,
is the mean isotopic value for baseline 1 and
is the mean isotopic value for baseline 2.
For equation 2)
is being corrected using equations in
Heuvel et al. 2024.
with
being the corrected value (bound by 0 and 1),
is the minimum
value calculated
using
add_alpha()
and being the maximum
value calculated using
add_alpha()
.
For equation 3)
This equation is a carbon source mixing model with C being
estimated using
c_1
, c_2
and calculated in equation 1.
For equation 4) and 5)
N are values from the consumer,
is
N values of baseline 1,
is
N values of baseline 2,
N is the trophic discrimination factor for N (i.e., mean of
3.4
),
tp is trophic position, and and/or
are the trophic levels of
baselines which are often a primary consumer (e.g.,
2
or 2.5
).
The data supplied to brms()
when using baselines at the same trophic level
(lambda
argument set to 1
) needs to have the following variables, d15n
,
n1
, n2
, l1
() which is usually
2
. If using baselines at
different trophic levels (lambda
argument set to 2
) the data frame needs
to have l1
and l2
with a numerical value for each trophic level (e.g.,
2
and 2.5
; and
).
returns model structure for two source model to be used in a
brms()
call.
two_source_model_arc()
two_source_model_arc()
Create priors for two source trophic position model derived from Post 2002.
two_source_priors(bp = FALSE)
two_source_priors(bp = FALSE)
bp |
logical value that controls whether informed priors are
supplied to the model for both |
returns priors for two source model to be used in a brms()
call.
two_source_model()
and brms::brms()
two_source_priors()
two_source_priors()
Create priors for trophic position using a two source model
with derived from Post 2002
and Heuvel et al. 2024.
two_source_priors_ar(bp = FALSE)
two_source_priors_ar(bp = FALSE)
bp |
logical value that controls whether informed priors are
supplied to the model for |
returns priors for two source model to be used in a brms()
call.
two_source_priors_ar()
two_source_priors_ar()
and carbon mixing modelCreate priors for trophic position using a two source model
with derived from Post 2002
and Heuvel et al. 2024.
two_source_priors_arc(bp = FALSE)
two_source_priors_arc(bp = FALSE)
bp |
logical value that controls whether informed priors are
supplied to the model for both |
returns priors for two source model to be used in a brms()
call.
two_source_priors_arc()
two_source_priors_arc()
Adjust priors for two source trophic position model derived from Post 2002.
two_source_priors_params( a = NULL, b = NULL, c1 = NULL, c1_sigma = NULL, c2 = NULL, c2_sigma = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
two_source_priors_params( a = NULL, b = NULL, c1 = NULL, c1_sigma = NULL, c2 = NULL, c2_sigma = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
a |
( |
b |
( |
c1 |
mean ( |
c1_sigma |
variance ( |
c2 |
mean ( |
c2_sigma |
variance ( |
n1 |
mean ( |
n1_sigma |
variance ( |
n2 |
mean ( |
n2_sigma |
variance ( |
dn |
mean ( |
dn_sigma |
variance ( |
tp_lb |
lower bound for priors for trophic position. Defaults to |
tp_ub |
upper bound for priors for trophic position. Defaults to |
sigma_lb |
lower bound for priors for |
sigma_ub |
upper bound for priors for |
bp |
logical value that controls whether informed priors are
supplied to the model for both |
We will use the following equations from Post 2002:
The random exponent (;
a
)
and shape parameters (;
b
) for . This prior
assumes a beta distribution.
The mean (c1
; ) and variance (
c1_sigma
; ) of
the mean for the first
for a given baseline.
This prior assumes a normal distributions.
The mean (c2
;) and variance (
c2_sigma
; ) of
the mean for the second
for a given baseline.
This prior assumes a normal distributions.
The mean (n1
; ) and variance (
n1_sigma
; ) of
the mean for the first
for a given baseline.
This prior assumes a normal distributions.
The mean (n2
;) and variance (
n2_sigma
; ) of
the mean for the second
N for a given baseline.
This prior assumes a normal distributions.
The mean (dn
; ) and variance (
dn_sigma
; ) of
N (i.e, trophic enrichment factor).
This prior assumes a normal distributions.
The lower (tp_lb
) and upper (tp_ub
) bounds for priors for
trophic position. This prior assumes a uniform distributions.
The lower (sigma_lb
) and upper (sigma_ub
) bounds for
variance (). This prior assumes a uniform distributions.
stanvars
object to be used with brms()
call.
two_source_priors()
, two_source_model()
, and brms::brms()
two_source_priors_params()
two_source_priors_params()
Create priors for trophic position using a two source model
with derived from Post 2002
and Heuvel et al. 2024.
two_source_priors_params_ar( a = NULL, b = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
two_source_priors_params_ar( a = NULL, b = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
a |
( |
b |
( |
n1 |
mean ( |
n1_sigma |
variance ( |
n2 |
mean ( |
n2_sigma |
variance ( |
dn |
mean ( |
dn_sigma |
variance ( |
tp_lb |
lower bound for priors for trophic position. Defaults to |
tp_ub |
upper bound for priors for trophic position. Defaults to |
sigma_lb |
lower bound for priors for |
sigma_ub |
upper bound for priors for |
bp |
logical value that controls whether informed baseline priors are
supplied to the model for |
We will use the following equations derived from Post 2002 and Heuvel et al. 2024:
For equation 1)
This equation is a carbon source mixing model with
is the isotopic value for consumer,
is the mean isotopic value for baseline 1 and
is the mean isotopic value for baseline 2. This
equation is added to the data frame using
add_alpha()
.
For equation 2)
is being corrected using equations in
Heuvel et al. 2024
with
being the corrected value (bound by 0 and 1),
is the minimum
value calculated
using
add_alpha()
and being the maximum
value calculated using
add_alpha()
.
For equation 3) and 4)
N are values from the consumer,
is
N values of baseline 1,
is
N values of baseline 2,
N is the trophic discrimination factor for N (i.e., mean of
3.4
),
tp is trophic position, and and/or
are the trophic levels of
baselines which are often a primary consumer (e.g.,
2
or 2.5
).
This function allows the user to adjust the priors for the following variables in the equation above:
The random exponent (;
a
)
and shape parameters (;
b
) for . This prior
assumes a beta distribution.
The mean (n2
;) and variance (
n2_sigma
; ) of
the second
N for a given baseline.
This prior assumes a normal distributions.
The mean (c1
;) and variance (
c1_sigma
; ) of
the second
C for a given baseline.
This prior assumes a normal distributions.
The mean (c2
;) and variance (
c2_sigma
; ) of
the second
C for a given baseline.
This prior assumes a normal distributions.
The mean (dn
; ) and variance (
dn_sigma
; ) of
N (i.e, trophic enrichment factor).
This prior assumes a normal distributions.
The lower (tp_lb
) and upper (tp_ub
) bounds for priors for
trophic position. This prior assumes a uniform distributions.
The lower (sigma_lb
) and upper (sigma_ub
) bounds for
variance (). This prior assumes a uniform distributions.
stanvars
object to be used with brms()
call.
two_source_priors_ar()
, two_source_model_ar()
, and brms::brms()
two_source_priors_params_ar()
two_source_priors_params_ar()
and carbon mixing modelAdjust priors for trophic position using a two source model
with derived from Post 2002
and Heuvel et al. 2024
two_source_priors_params_arc( a = NULL, b = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, c1 = NULL, c1_sigma = NULL, c2 = NULL, c2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
two_source_priors_params_arc( a = NULL, b = NULL, n1 = NULL, n1_sigma = NULL, n2 = NULL, n2_sigma = NULL, c1 = NULL, c1_sigma = NULL, c2 = NULL, c2_sigma = NULL, dn = NULL, dn_sigma = NULL, tp_lb = NULL, tp_ub = NULL, sigma_lb = NULL, sigma_ub = NULL, bp = FALSE )
a |
( |
b |
( |
n1 |
mean ( |
n1_sigma |
variance ( |
n2 |
mean ( |
n2_sigma |
variance ( |
c1 |
mean ( |
c1_sigma |
variance ( |
c2 |
mean ( |
c2_sigma |
variance ( |
dn |
mean ( |
dn_sigma |
variance ( |
tp_lb |
lower bound for priors for trophic position. Defaults to |
tp_ub |
upper bound for priors for trophic position. Defaults to |
sigma_lb |
lower bound for priors for |
sigma_ub |
upper bound for priors for |
bp |
logical value that controls whether informed baseline priors are
supplied to the model for |
We will use the following equations derived from Post 2002 and Heuvel et al. 2024:
For equation 1)
This equation is a carbon source mixing model with
is the isotopic value for consumer,
is the mean isotopic value for baseline 1 and
is the mean isotopic value for baseline 2.
For equation 2)
is being corrected using equations in
Heuvel et al. 2024.
with
being the corrected value (bound by 0 and 1),
is the minimum
value calculated
using
add_alpha()
and being the maximum
value calculated using
add_alpha()
.
For equation 3)
This equation is a carbon source mixing model with C being
estimated using
c_1
, c_2
and calculated in equation 1.
For equation 4) and 5)
N are values from the consumer,
is
N values of baseline 1,
is
N values of baseline 2,
N is the trophic discrimination factor for N (i.e., mean of
3.4
),
tp is trophic position, and and/or
are the trophic levels of
baselines which are often a primary consumer (e.g.,
2
or 2.5
).
This function allows the user to adjust the priors for the following variables in the equation above:
The random exponent (;
a
)
and shape parameters (;
b
) for . This prior
assumes a beta distribution.
The mean (n2
;) and variance (
n2_sigma
; ) of
the second
N for a given baseline.
This prior assumes a normal distributions.
The mean (c1
;) and variance (
c1_sigma
; ) of
the second
C for a given baseline.
This prior assumes a normal distributions.
The mean (c2
;) and variance (
c2_sigma
; ) of
the second
C for a given baseline.
This prior assumes a normal distributions.
The mean (dn
; ) and variance (
dn_sigma
; ) of
N (i.e, trophic enrichment factor).
This prior assumes a normal distributions.
The lower (tp_lb
) and upper (tp_ub
) bounds for priors for
trophic position. This prior assumes a uniform distributions.
The lower (sigma_lb
) and upper (sigma_ub
) bounds for
variance (). This prior assumes a uniform distributions.
stanvars
object to be used with brms()
call.
two_source_priors_arc()
, two_source_model_arc()
, and brms::brms()
two_source_priors_params_ar()
two_source_priors_params_ar()