Title: Quantitative Fatty Acid Signature Analysis
Version: 1.2.1
Date: 2024-08-27
Description: Accurate estimates of the diets of predators are required in many areas of ecology, but for many species current methods are imprecise, limited to the last meal, and often biased. The diversity of fatty acids and their patterns in organisms, coupled with the narrow limitations on their biosynthesis, properties of digestion in monogastric animals, and the prevalence of large storage reservoirs of lipid in many predators, led to the development of quantitative fatty acid signature analysis (QFASA) to study predator diets.
Depends: R (≥ 3.5.0)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports: stats, Rsolnp, boot, futile.logger, gamlss, gamlss.dist, vegan, bootstrap, Compositional, TMB, compositions, MASS, dplyr, mvtnorm,
LinkingTo: TMB, Rcpp, RcppEigen,
RoxygenNote: 7.3.2
VignetteBuilder: rmarkdown, knitr
Suggests: plyr, knitr, rmarkdown, testthat, gtools
BugReports: https://github.com/cstewartGH/QFASA/issues
URL: https://CRAN.R-project.org/package=QFASA
NeedsCompilation: yes
Packaged: 2024-08-27 17:32:37 UTC; cstewart
Author: Connie Stewart [cre, aut, cph], Sara Iverson [aut, cph], Chris Field [aut], Don Bowen [aut], Wade Blanchard [aut], Shelley Lang [aut], Justin Kamerman [aut], Hongchang Bao [ctb], Holly Steeves [aut], Jennifer McNichol [aut], Tyler Rideout [aut]
Maintainer: Connie Stewart <connie.stewart@unb.ca>
Repository: CRAN
Date/Publication: 2024-08-27 19:40:02 UTC

QFASA: A package for Quantitative Fatty Acid Signature Analysis

Description

Accurate estimates of the diets of predators are required in many areas of ecology, but for many species current methods are imprecise, limited to the last meal, and often biased. The diversity of fatty acids and their patterns in organisms, coupled with the narrow limitations on their biosynthesis, properties of digestion in monogastric animals, and the prevalence of large storage reservoirs of lipid in many predators, led us to propose the use of quantitative fatty acid signature analysis (QFASA) to study predator diets.


Returns the distance between two compositional vectors using Aitchison's distance measure.

Description

Returns the distance between two compositional vectors using Aitchison's distance measure.

Usage

AIT.dist(x.1, x.2)

Arguments

x.1

compositional vector

x.2

compositional vector

References

Aitchison, J., (1992) On criteria for measures of compositional difference. Mathematical Geology, 24(4), pp.365-379.

Connie Stewart (2017) An approach to measure distance between compositional diet estimates containing essential zeros, Journal of Applied Statistics, 44:7, 1137-1152, DOI: 10.1080/02664763.2016.1193846


Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and Aitchison distance measure.

Description

Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and Aitchison distance measure.

Usage

AIT.more(alpha, predator, prey.quantiles)

Arguments

alpha

compositional QFASA diet estimate.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.


Used in solnp() as the objective function to be minimized when Aitchison distance measure is chosen.

Description

Used in solnp() as the objective function to be minimized when Aitchison distance measure is chosen.

Usage

AIT.obj(alpha, predator, prey.quantiles)

Arguments

alpha

vector over which minimization takes place.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.


Fatty acid calibration coefficients.

Description

Fatty acid calibration coefficients.

Usage

CC

Format

A data frame with 66 observations and 2 variables:

FA

fatty acid names

CC

calibration coefficient for corresponding fatty acid


Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and chi-square distance measure.

Description

Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and chi-square distance measure.

Usage

CS.more(alpha, predator, prey.quantiles, gamma)

Arguments

alpha

compositional QFASA diet estimate.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.

gamma

power transform exponent (see chisq.dist()).


Used in solnp() as the objective function to be minimized when chi-square distance measure is chosen. Unlike AIT.obj() and KL.obj(), does not require modifying zeros.

Description

Used in solnp() as the objective function to be minimized when chi-square distance measure is chosen. Unlike AIT.obj() and KL.obj(), does not require modifying zeros.

Usage

CS.obj(alpha, predator, prey.quantiles, gamma)

Arguments

alpha

vector over which minimization takes place.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.

gamma

power transform exponent (see chisq.dist()).


List of fatty acids used in sample prey and predator data sets, preyFAs and predatorFAs respectively.

Description

List of fatty acids used in sample prey and predator data sets, preyFAs and predatorFAs respectively.

Usage

FAset

Format

A data frame with 39 observations and 1 variable:

FA

Fatty acid name


Returns the distance between two compositional vectors using Kullback–Leibler distance measure.

Description

Returns the distance between two compositional vectors using Kullback–Leibler distance measure.

Usage

KL.dist(x.1, x.2)

Arguments

x.1

compositional vector

x.2

compositional vector

References

S.J. Iverson, C. Field, W.D. Bowen, and W. Blanchard (2004) Quantitative fatty acid signature analysis: A new method of estimating predator diets, Ecological Monographs 72, pp. 211-235.


Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and Kullback-Leibler distance measure.

Description

Used to provide additional information on various model components evaluated at the optimal solution, i.e., using the QFASA diet estimates and Kullback-Leibler distance measure.

Usage

KL.more(alpha, predator, prey.quantiles)

Arguments

alpha

compositional QFASA diet estimate.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.


Used in solnp() as the objective function to be minimized when Kullback–Leibler distance measure is chosen.

Description

Used in solnp() as the objective function to be minimized when Kullback–Leibler distance measure is chosen.

Usage

KL.obj(alpha, predator, prey.quantiles)

Arguments

alpha

vector over which minimization takes place.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.


Returns the multivariate mean FA signature of each prey group entered into the QFASA model. Result can be passed to prey.mat in p.QFASA().

Description

Returns the multivariate mean FA signature of each prey group entered into the QFASA model. Result can be passed to prey.mat in p.QFASA().

Usage

MEANmeth(prey.mat)

Arguments

prey.mat

matrix containing the FA signatures of the prey. The first column indexes the prey group.


Computes within species variance-covariance matrices on transformed scaled, along with a pooled estimate.

Description

Computes within species variance-covariance matrices on transformed scaled, along with a pooled estimate.

Usage

POOLVARmeth(prey.mat)

Arguments

prey.mat

matrix containing transformed FA signatures of the prey. Note that the first column indexes prey type.

Value

Returns the variance-covariance matrix of each prey type as well as a pooled estimate of the variance-covariance matrix


Returns sum(alpha) and used in solnp().

Description

Returns sum(alpha) and used in solnp().

Usage

QFASA.const.eqn(alpha, predator, prey.quantiles, gamma)

Arguments

alpha

vector over which minimization takes place.

predator

fatty acid signature of predator.

prey.quantiles

matrix of fatty acid signatures of prey. Each row contains an individual prey signature from a different species.

gamma

power transform exponent (see chisq.dist).


Generate bootstrap replicates of diet proportion estimates for given prey species

Description

Generate bootstrap replicates of diet proportion estimates for given prey species

Usage

Tstar.beta(p.k, theta.boot, mu.null, phi.boot, R.boot)

Value

list of diet proportion replicates


Returns diet estimates corresponding to a sample of predators based on a backward elimination algorithm that chooses the prey species to be included in the modelling.

Description

Returns diet estimates corresponding to a sample of predators based on a backward elimination algorithm that chooses the prey species to be included in the modelling.

Usage

backward.elimination(
  pred.mat,
  prey.mat,
  cal.vec,
  FC,
  ext.fa,
  k = 2,
  cutoff = 0.1,
  silence = FALSE
)

Arguments

pred.mat

matrix containing the FA signatures of the predators, where each row corresponds to a predator and each column to a FA.

prey.mat

data frame containing the FA signatures of the prey, where each row corresponds to a single individual prey. The first column must index the prey group, while the remaining columns correspond to FAs.

cal.vec

numeric vector of calibration coefficients corresponding to the FAs contained in the modelling subset ext.fa. A vector of ones in the length of ext.fa may be used for modelling without calibration coefficients.

FC

numeric vector of the average lipid contents for each prey group, in the order of the alphabetized prey groups. vector of ones equal in length to the number of prey groups may be used for modelling without adjustment for fat content.

ext.fa

character vector containing the subset of FAs to be used in modelling.

k

scaling factor to be used in calculating the value of the information criterion (IC). The default value of 2 corresponds to the Akaike Information Criterion. For a sample of size n, k = log(n) corresponds to the Bayesian Information Criterion. As this factor is numeric, values corresponding to other IC may be used freely.

cutoff

numeric proportion to be used as the threshold for the candidacy for removal of a species in backward elimination. If initial diet estimates for any individual predator find a species to be present in proportions greater than this threshold, that species will not be considered for removal from the model. This reduces computation times and safeguards against the removal of species which may be present in the diets of few predators. All species are considered candidates for removal at a value of 1, while lower values are more conservative. The default value is 0.1.

silence

if true, additional information is printed. Default is false.

Details

The function uses a backward elimination algorithm and the simplified MLE method to choose the prey species to be included in the model and then returns the diet estimates corresponding to these species.

Value

A list with components:

Diet_Estimates

A matrix of the diet estimates for each predator where each row corresponds to a predator and each column to a prey species. The estimates are expressed as proportions summing to one.

Selection_Order

A data frame summarizing each step of the algorithm, giving the order of species removal and the corresponding IC values.

Selection_Tables

A list containing a data frame for each step of the selection process, providing the IC values associated with removing any one candidate species at that step.

See Also

forward.selection()

Examples


 ## This example takes some time to run.
 ## Please uncomment code below to run.

#library(dplyr)
#library(compositions)
## Package data: FAs
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Package data: Prey
#data(preyFAs)
#prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]
#prey.sub=prey.sub/apply(prey.sub,1,sum)
#group=as.vector(preyFAs$Species)
#prey.sub = cbind(group,prey.sub)
#sort.preytype <- order(prey.sub[, 1])
#prey.matrix <- prey.sub[sort.preytype,]

## Package data: Predators
#data(predatorFAs)
#tombstone.info = predatorFAs[,1:4]
#predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
#npredators = nrow(predator.matrix)

## Package data: Fat content
#FC = preyFAs[,c(2,3)]
#FC = as.vector(tapply(FC$lipid,FC$Species,mean,na.rm=TRUE))

## Package data: Calibration coefficients
#data(CC)
#cal.vec = CC[,2]
#cal.mat = replicate(npredators, cal.vec)
#rownames(cal.mat) <- CC$FA
#names(cal.vec) <- rownames(cal.mat)

## QFASA (KL)
#sample.qfasa <- p.QFASA(predator.matrix,MEANmeth(prey.matrix),cal.mat,
#dist.meas = 1,gamma=1,FC,
#start.val = rep(1,nrow(MEANmeth(prey.matrix))),fa.set)

## Backward Elimination
#sample.be <- backward.elimination(predator.matrix, prey.matrix, cal.vec,FC,
#fa.set,cutoff = 0.01)

## Output
#be.estimates <- sample.be$`Diet Estimates`

Sample example of balanced repeatability diet estimates data with only two repeated measurements per predator.

Description

Sample example of balanced repeatability diet estimates data with only two repeated measurements per predator.

Usage

bal.diet.data

Format

A data frame with 100 predator diets (50 unique predators) and 13 variables:

Seal.ID

Predator (1 to 50)

Year

Either 1 or 2

capelin

estimated diet proportion

coho

estimated diet proportion

eulachon

estimated diet proportion

herring

estimated diet proportion

mackerel

estimated diet proportion

pilchard

estimated diet proportion

pollock

estimated diet proportion

sandlance

estimated diet proportion

squid

estimated diet proportion

surfsmelt_s

estimated diet proportion

sufsmelt_lg

estimated diet proportion


Measure of Repeatability for Diet Estimates (Balanced Case)

Description

Computes a measure of repeatability for a sample of predators with repeated diet estimate measurements (Balanced Case)

Usage

bal.rep.CI(
  data,
  B,
  R,
  CI = TRUE,
  alpha,
  prey.database,
  fatcont.mat,
  dist.meas,
  ext.fa,
  gamma.QFASA = 1,
  gamma.rho = 1
)

Arguments

data

data frame of diet estimates. First column must denote the predator and second column the second factor (eg. year or season). Must contain the same number of repeated measurements for each predator.

B

number of pseudo predators samples to generate for bias calculation. Default is set to 50 because is slow to run.

R

number of bootstrap samples (i.e. R samples for each generated sample of pseudo predators). Default is set to 100 because it is slow to run.

CI

indicates if a confidence interval for rho is to be calculated. Default is FALSE since this is time consuming to obtain.

alpha

a (1-alpha/2)X100 percent confidence interval is calculated for rho if CI=TRUE.

prey.database

prey data base that was used to compute the QFASA diet estimates in data. Will be used to generate pseudo predators.

fatcont.mat

data frame or matrix of length equal to the number of prey FA signatures in prey data base. First column is name of species and second column is lipid.

dist.meas

distance measure to use in p.QFASA.

ext.fa

subset of FAs to use.

gamma.QFASA

if dist.meas=3, gamma is required. Default is 1.

gamma.rho

value of gamma to be used to compute CS distance in repeatablity functions. Default is 1.

Value

Bias corrected measure of repeatability, estimate of the bias and (if CI=TRUE) a confidence interval for the true repeatability.


Finds the species combination with the best (lowest) IC value achievable by dropping a single species from the prey.mat. Used for each iteration of backward elimination.

Description

Finds the species combination with the best (lowest) IC value achievable by dropping a single species from the prey.mat. Used for each iteration of backward elimination.

Usage

bestBackwardModel(
  pred.mat,
  prey.mat,
  cal.vec,
  fat.vec,
  ext.fa,
  starting.estimates,
  k = 2,
  cutoff = 0.01,
  silence = FALSE
)

Finds the species combination with the best# (lowest) IC value achievable by adding a single species from full.prey.mat. Used for each iteration of forward selection.

Description

Finds the species combination with the best# (lowest) IC value achievable by adding a single species from full.prey.mat. Used for each iteration of forward selection.

Usage

bestForwardModel(
  pred.mat,
  full.prey.mat,
  prey.mat,
  cal.vec,
  fat.vec,
  ext.fa,
  k = 2,
  silence = FALSE
)

Find the pair of starting species with the best (lowest) IC value among all possible pairs of species in prey.mat Used in forward selection when no starting species are specified

Description

Find the pair of starting species with the best (lowest) IC value among all possible pairs of species in prey.mat Used in forward selection when no starting species are specified

Usage

bestSubset(
  pred.mat,
  prey.mat,
  cal.vec,
  fat.vec,
  ext.fa,
  k = 2,
  silence = FALSE
)

Returns individual confidence intervals and simultaneous confidence intervals based on the zero-inflated beta distribution (not bias corrected - see note below).

Description

For details see: Stewart, C. (2013) Zero-Inflated Beta Distribution for Modeling the Proportions in Quantitative Fatty Acid Signature Analysis. Journal of Applied Statistics, 40(5), 985-992.

Usage

beta.meths.CI(
  predator.mat,
  prey.mat,
  cal.mat = rep(1, length(ext.fa)),
  dist.meas,
  noise = 0,
  nprey,
  R.p,
  R.ps,
  R,
  p.mat,
  alpha,
  FC = rep(1, nrow(prey.mat)),
  ext.fa
)

Arguments

predator.mat

matrix containing the fatty acid signatures of the predators.

prey.mat

prey database. A dataframe with first column a Species label and other columns fatty acid proportions. Fatty acid proportions are compositional.

cal.mat

matrix of calibration coefficients of predators. Each column corresponds to a different predator. At least one calibration coefficient vector must be supplied.

dist.meas

distance measure to use for estimation: 1=KL, 2=AIT or 3=CS

noise

proportion of noise to include in the simulation.

nprey

number of prey to sample from the the prey database when generating pseudo-predators for the nuisance parameter estimation.

R.p

number of beta diet distributions to generate for the nuisance parameters.

R.ps

number of pseudo predators to generate when estimating nuisance parameters.

R

number of bootstrap replicates to use when generating p-values for confidence interval estimation.

p.mat

matrix of predator diet estimates for which we are trying to find confidence intervals.

alpha

confidence interval confidence level.

FC

vector of prey fat content. Note that this vector is passed to the gen.pseudo.seals which expects fat content values for individual prey samples while pseudo.seal and p.QFASA expect a species average.

ext.fa

subset of fatty acids to be used to obtain QFASA diet estimates.

Details

Note:

Value

Individual confidence intervals and simultaneous confidence intervals based on the zero-inflated beta distribution. These intervals are biased and should be corrected using the output from bias.all. ci.l.1 and ci.u.1 contain the simultaneous confidence intervals.

References

Stewart, C. (2013) Zero-inflated beta distribution for modeling the proportions in quantitative fatty acid signature analysis. Journal of Applied Statistics, 40(5), 985-992.

Examples

#####  beta.meths.CI is deprecated.  Please use conf.meth! #####
## Fatty Acids
data(FAset)
fa.set = as.vector(unlist(FAset))

## Predators
data(predatorFAs)
tombstone.info = predatorFAs[,1:4]
predator.matrix = predatorFAs[, fa.set]
npredators = nrow(predator.matrix)

## Prey
prey.sub = preyFAs[, fa.set]
prey.sub = prey.sub / apply(prey.sub, 1, sum)
group = as.vector(preyFAs$Species)
prey.matrix.full = cbind(group,prey.sub)
prey.matrix = MEANmeth(prey.matrix.full)

## Calibration Coefficients
data(CC)
cal.vec = CC[CC$FA %in% fa.set, 2]
cal.mat = replicate(npredators, cal.vec)

# Note: uncomment examples to run. CRAN tests fail because execution time > 5 seconds
# set.seed(1234)
# diet.est <- p.QFASA(predator.mat = predator.matrix,
#                     prey.mat = prey.matrix,
#                     cal.mat = cal.mat,
#                     dist.meas = 2,
#                     start.val = rep(1,nrow(prey.matrix)),
#                     ext.fa = fa.set)[['Diet Estimates']]
#
# ci = beta.meths.CI(predator.mat = predator.matrix,
#                    prey.mat = prey.matrix.full,
#                    cal.mat = cal.mat,
#                    dist.meas = 2,
#                    nprey = 10,
#                    R.p = 1,
#                    R.ps = 10, #
#                    R = 1,
#                    p.mat = diet.est,
#                    alpha = 0.05,
#                    ext.fa = fa.set)


Calculate p-value of a given prey type diet proportion under the predator diets and estimated diet distribution provided.

Description

Calculate p-value of a given prey type diet proportion under the predator diets and estimated diet distribution provided.

Usage

beta.pval.k(par.list, R, diet.test.k, p.mat, k)

Arguments

par.list

a list of R.p lists of I beta distribution parameters phi and theta that define diet proportion estimates for each of the prey species. Effectively R.p beta distibutions for each of the I prey species which we bootstrap to calculate p-values.

R

number of bootstrap replicates to use in p-value estimation.

diet.test.k

diet proportion for which we want the p-value

p.mat

predator diet estimates.

k

prey species index 1..I

Value

p-value p-value


Calculate bias correction for confidence intervals from beta.meths.CI.

Description

Calculate bias correction for confidence intervals from beta.meths.CI.

Usage

bias.all(
  p.mat,
  prey.mat,
  cal.mat = rep(1, length(ext.fa)),
  fat.cont = rep(1, nrow(prey.mat)),
  R.bias,
  noise,
  nprey,
  specify.noise,
  dist.meas,
  ext.fa
)

Arguments

p.mat

matrix containing the fatty acid signatures of the predators.

prey.mat

matrix containing a representative fatty acid signature

cal.mat

matrix of calibration factors where the i th column is to be used with the i th predator. If modelling is to be done without calibration coefficients, simply pass a vector or matrix of ones.

fat.cont

prey fat content

R.bias

bootstrap replicates

noise

noise

nprey

number of prey

specify.noise

noise

dist.meas

distance measure

ext.fa

subset of FA's to use.

Value

Row 1 is Lambda CI, row 2 is Lambda skew, and row 3 is Beta CI

Examples

## Fatty Acids
data(FAset)
fa.set = as.vector(unlist(FAset))

## Predators
data(predatorFAs)
tombstone.info = predatorFAs[,1:4]
predator.matrix = predatorFAs[, fa.set]
npredators = nrow(predator.matrix)

## Prey
prey.sub = preyFAs[, fa.set]
prey.sub = prey.sub / apply(prey.sub, 1, sum)
group = as.vector(preyFAs$Species)
prey.matrix.full = cbind(group,prey.sub)
prey.matrix = MEANmeth(prey.matrix.full)

## Calibration Coefficients
data(CC)
cal.vec = CC[CC$FA %in% fa.set, 2]
cal.mat = replicate(npredators, cal.vec)

# Note: uncomment examples to run. CRAN tests fail because execution time > 5 seconds
# diet.est <- p.QFASA(predator.mat = predator.matrix,
#                     prey.mat = prey.matrix,
#                     cal.mat = cal.mat,
#                     dist.meas = 2,
#                     start.val = rep(1,nrow(prey.matrix)),
#                     ext.fa = fa.set)[['Diet Estimates']]
#
# bias <- bias.all(p.mat = diet.est,
#                  prey.mat = prey.matrix.full,
#                  cal.mat = cal.mat,
#                  R.bias = 10,
#                  noise = 0,
#                  nprey = 50,
#                  dist.meas = 2,
#                  ext.fa = fa.set)


Calculate bias correction for confidence intervals.

Description

Calculate bias correction for confidence intervals.

Usage

bias.comp(diet.est, prey.mat, R.bias, dist.meas, ext.fa, gamma = 1)

Arguments

diet.est

predator diet estimates

prey.mat

matrix of prey FA signatures

R.bias

number of replicates

dist.meas

distance measure

ext.fa

subset of FA's to use.

Value

estimate of bias for each prey type


Find simultaneous and individual confidence intervals for diet proportions of a single prey species i.e. solve f(pio) = PVAL(pio) = alpha1 and f(pio) = PVAL(pio) = alpha2 using bisection.

Description

Assumptions: alpha1 < alpha2

Usage

bisect.beta.lim(alpha1, alpha2, par.list, R, p.mat, k)

Arguments

alpha1

simultaneous confidence level

alpha2

individual confidence level

par.list

a list of R.p lists of I beta distribution parameters phi and theta that define diet proportion estimates for each of the prey species. Effectively R.p beta distibutions for each of the I prey species from which we bootstrap to calculate p-values.

R

number of bootstrap replicates to use in p-value estimation.

p.mat

predator diet estimates.

k

prey species index 1..I

Details

Note: Tried to minimize number of times have to compute a pvalue since very slow.

Value

upper and lower limits for individual and simultaneous intervals respectively.


Called by create.d.mat() to compute the chi-square distance.

Description

Called by create.d.mat() to compute the chi-square distance.

Usage

chisq.CA(x1, x2)

Arguments

x1

vector

x2

vector


Returns the distance between two compositional vectors using the chi-square distance.

Description

Returns the distance between two compositional vectors using the chi-square distance.

Usage

chisq.dist(x.1, x.2, gamma)

Arguments

x.1

compositional vector

x.2

compositional vector

gamma

power transform taken to be 1.

References

Stewart, C., Iverson, S. and Field, C. (2014) Testing for a change in diet using fatty acid signatures. Environmental and Ecological Statistics 21, pp. 775-792.

Connie Stewart (2017) An approach to measure distance between compositional diet estimates containing essential zeros, Journal of Applied Statistics, 44:7, 1137-1152, DOI: 10.1080/02664763.2016.1193846


Generate bootstrap replicates of diet proportion estimates for given prey species

Description

Generate bootstrap replicates of diet proportion estimates for given prey species

Usage

comp.Tstar.beta(p.k, theta.boot, mu.null, phi.boot, R.boot)

Arguments

p.k

list of predator diet proportions for prey species k

theta.boot

distribution parameter

mu.null

distribution parameter

phi.boot

distribution parameter

R.boot

number of bootstrap replicates to create

Value

list of diet proportion replicates


Calculate p-value corresponding to a specified null value using bootstrapping

Description

Calculate p-value corresponding to a specified null value using bootstrapping

Usage

comp.beta.pval.k(par.list, R, diet.test.k, p.mat, k)

Arguments

par.list

a list of R.p lists of I beta distribution parameters phi and theta that define diet proportion estimates for each of the prey species. Effectively R.p beta distributions for each of the I prey species which we bootstrap to calculate p-values.

R

number of bootstrap replicates to use in p-value estimation.

diet.test.k

null value

p.mat

predator diet estimates.

k

prey species index 1..I

Value

p-value p-value


Generate pseudo predators with ith predator having true diet given by ith row of diet.null.mat.

Description

Generate pseudo predators with ith predator having true diet given by ith row of diet.null.mat.

Usage

comp.gen.pseudo.seals(prey.mat, diet.null.mat, cal.mat, fat.cont, noise, nprey)

Arguments

prey.mat

matrix containing a representative FA signature from each prey group (usually the mean). The first column must index the prey group.

diet.null.mat

null diet

cal.mat

matrix of calibration coefficients where the i th column is to be used with the i th predator.

fat.cont

vector of fat content

noise

proportion of noise to add to the simulation.

nprey

number of prey to sample.


Bootstrap statistic function: in this case it is the mean (meanBEZI) of the fitted (gamlss) ZIB distribution.

Description

Bootstrap statistic function: in this case it is the mean (meanBEZI) of the fitted (gamlss) ZIB distribution.

Usage

comp.p.beta(data)

Arguments

data

data

Value

the expected value of the response for a fitted model


Repeatability in Diet Estimates

Description

Computes a measure of repeatability for a sample of predators with repeated diet estimate measurements.

Usage

comp.rep(
  data,
  prey.database,
  fatcont.mat,
  dist.meas,
  ext.fa,
  B = 50,
  R = 100,
  CI = FALSE,
  alpha = 0.05,
  gamma.QFASA = 1,
  gamma.rho = 1
)

Arguments

data

data frame of diet estimates. First column must denote the predator and second column the second factor (eg. year or season).

prey.database

prey data base that was used to compute the QFASA diet estimates in data. Will be used to generate pseudo predators.

fatcont.mat

data frame or matrix of length equal to the number of prey FA signatures in prey data base. First column is name of species and second column is lipid.

dist.meas

distance measure to use in p.QFASA.

ext.fa

subset of FAs to use.

B

number of pseudo predators samples to generate for bias calculation. Default is set to 50 because is slow to run.

R

number of bootstrap samples (i.e. R samples for each generated sample of pseudo predators). Default is set to 100 because it is slow to run.

CI

indicates if a confidence interval for rho is to be calculated. Default is FALSE since this is time consuming to obtain.

alpha

a (1-alpha/2)X100 percent confidence interval is calculated for rho if CI=TRUE.

gamma.QFASA

if dist.meas=3, gamma is required. Default is 1.

gamma.rho

value of gamma to be used to compute CS distance in repeatablity functions. Default is 1.

Value

Bias corrected measure of repeatability, estimate of the bias and (if CI=TRUE) a confidence interval for the true repeatability.

References

"Repeatability for Compositional Diet Estimates with Zeros". Contact Connie Stewart (cstewart@unb.ca).

Examples


 ##  These examples take some time to run.
 ##  Please uncomment code below to run them.

# data(preyFAs)
# data(FAset)

## Balanced Diet Data

#my.preybase <- preyFAs[,-c(1,3)]
#my.preybase[,-1] <- my.preybase[,-1]/rowSums(my.preybase[,-1])

#set.seed(10)

#comp.rep(data = bal.diet.data,prey.database=my.preybase,
#fatcont.mat = as.data.frame(preyFAs[,c(2,3)]),dist.meas=2,
#ext.fa = as.vector(unlist(FAset)))

## Unbalanced Diet Data

# my.preybase <- preyFAs[,-c(1,3)]
# my.preybase[,-1] <- my.preybase[,-1]/rowSums(my.preybase[,-1])

# set.seed(10)

# comp.rep(unbal.diet.data,my.preybase,as.data.frame(preyFAs[,c(2,3)]),2,
# as.vector(unlist(FAset)))

Confidence Intervals for Diet Proportions

Description

Returns simultaneous confidence intervals for the diet of each species in the prey database.

Usage

conf.meth(
  predator.mat,
  prey.mat,
  p.mat,
  cal.mat = rep(1, length(ext.fa)),
  dist.meas,
  FC = rep(1, nrow(prey.mat)),
  alpha = 0.05,
  nprey = 30,
  R.p = 1,
  R.ps = 100,
  R = 100,
  R.bias = 100,
  noise = 0,
  ext.fa
)

Arguments

predator.mat

matrix containing fatty acid signatures of the predators with fatty acids summing to one.

prey.mat

prey database. A data frame with first column a Species label and other columns fatty acid proportions summing to one..

p.mat

matrix of previously computed predator diet estimates needed for confidence interval calculation.

cal.mat

matrix or vector of calibration coefficients of predators. Each COLUMN corresponds to a different predator. Default is a vector of ones. The number of fatty acids should be the same as the number of predator and prey fatty acids.

dist.meas

distance measure to use for estimation: 1=KL, 2=AIT or 3=CS

FC

vector of prey fat content, one for each individual in prey database. Note that this vector is passed to the gen.pseudo.seals which expects fat content values for individual prey samples while pseudo.seal and p.QFASA expect a species average. Default is a vector of ones.

alpha

1-alpha is the family-wise or overall confidence level. Default is 0.05 for an overall confidence level of 0.95.

nprey

number of prey to sample from the prey database when generating pseudo predators for the nuisance parameter estimation using original QFASA simulating code. Default is 30.

R.p

number of times to re-sample data. Due to algorithm being slow, the default parameter is 1.

R.ps

number of pseudo predators to generate when estimating nuisance parameters. Default is 100.

R

number of bootstrap replicates to use when generating p-values for confidence interval estimation. Default is 100.

R.bias

number of replicates for bias computation. Default is 100.

noise

proportion of noise to include in the generation of pseudo predators using original QFASA simulating code.

ext.fa

subset of fatty acids to be used. These should be the same as those in predator.mat, prey.mat and cal.mat.

Details

Intervals are biased corrected as recommended in Stewart, C. (2013). Intervals are slow to obtain, particularly if there are many prey types. See vignette on parallel execution to speed up calculations.

Value

Simultaneous (1-alpha)*100 zero-inflated beta distribution.

References

Stewart, C. (2013) Zero-inflated beta distribution for modeling the proportions in quantitative fatty acid signature analysis. Journal of Applied Statistics, 40(5), 985-992.

Examples

## Reducing prey database to three species so that code below will run more quickly.
## Please uncomment code to run.

#set.seed(1234)
## Fatty Acids
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Sample of Predators
#data(predatorFAs)
#predator.matrix = predatorFAs[, -c(1:4)]
#predator.matrix.ext = predatorFAs[,fa.set]
#predator.matrix.ext = predator.matrix.ext/rowSums(predator.matrix.ext)

# Prey Database
#prey.red =
#preyFAs[preyFAs$Species=="capelin"|preyFAs$Species=="herring"|preyFAs$Species=="sandlance", ]
#prey.red = prey.red[,-c(1,3)]
#prey.red.ext = prey.red[,c("Species",fa.set)]
#prey.red.ext[,-1] <- prey.red.ext[,-1]/rowSums(prey.red.ext[,-1])
#prey.red.ext.means = MEANmeth(prey.red.ext)

## Calibration Coefficients

#data(CC)
#cal.vec = CC[CC$FA %in% fa.set, 2]

#diet.est <- p.QFASA(predator.mat = predator.matrix.ext,
#                    prey.mat = prey.red.ext.means,
#                    cal.mat = cal.vec,
#                   dist.meas = 2,
#                    start.val = rep(1,nrow(prey.red.ext.means)),
#                    ext.fa = fa.set)[['Diet Estimates']]

## conf.meth needs the full prey matrix unlike p.QFASA.
#ci <- conf.meth(predator.mat = predator.matrix.ext, prey.mat = prey.red.ext, cal.mat = cal.vec,
#          p.mat = diet.est, dist.meas = 2, FC = preyFAs[,3],ext.fa = fa.set)

Called by testfordiff.ind.boot.fun() to create a matrix of distances.

Description

Called by testfordiff.ind.boot.fun() to create a matrix of distances.

Usage

create.d.mat(Y.1, Y.2)

Arguments

Y.1

vector

Y.2

vector


CALCULATE CS DISTANCE BETWEEN EACH TWO PREDATORS IN dataset

Description

CALCULATE CS DISTANCE BETWEEN EACH TWO PREDATORS IN dataset

Usage

cs_distance.mat(dataset, alpha = 1)

Bootstrap ran.gen function:

Description

Bootstrap ran.gen function:

Bootstrap ran.gen function:

Usage

data.sim.beta(data, mle)

data.sim.beta(data, mle)

Roxygen commands

Description

Roxygen commands

Usage

dummy()

Get nll and IC values for a pair of species (this is used in forward selection if the starting species are not specified; used on a list of all possible combinations of two species)

Description

Get nll and IC values for a pair of species (this is used in forward selection if the starting species are not specified; used on a list of all possible combinations of two species)

Usage

evaluateCombination(
  species.index,
  species.list,
  pred.mat,
  prey.mat,
  cal.vec,
  fat.vec,
  ext.fa,
  k = 2
)

Get nll and IC values for a given model (note that the model is determined by the species included in prey.mat - prey.mat is adjusted to add or remove species before entering this function

Description

Get nll and IC values for a given model (note that the model is determined by the species included in prey.mat - prey.mat is adjusted to add or remove species before entering this function

Usage

evaluateModel(pred.mat, prey.mat, cal.vec, fat.vec, ext.fa, k = 2)

Returns diet estimates corresponding to a sample of predators based on a forward selection algorithm that chooses the prey species to be included in the modelling.

Description

Returns diet estimates corresponding to a sample of predators based on a forward selection algorithm that chooses the prey species to be included in the modelling.

Usage

forward.selection(
  pred.mat,
  prey.mat,
  cal.vec,
  FC,
  ext.fa,
  k = 2,
  min.spec = 5,
  starting.spec = NULL,
  silence = FALSE
)

Arguments

pred.mat

matrix containing the FA signatures of the predators, where each row corresponds to a predator and each column to a FA.

prey.mat

data frame containing the FA signatures of the prey, where each row corresponds to a single individual prey. The first column must index the prey group, while the remaining columns correspond to FAs.

cal.vec

numeric vector of calibration coefficients corresponding to the FAs contained in the modelling subset ext.fa. A vector of ones in the length of ext.fa may be used for modelling without calibration coefficients.

FC

numeric vector of the average lipid contents for each prey group, in the order of the alphabetized prey groups. vector of ones equal in length to the number of prey groups may be used for modelling without adjustment for fat content.

ext.fa

character vector containing the subset of FAs to be used in modelling.

k

scaling factor to be used in calculating the value of the information criterion (IC). The default value of 2 corresponds to the Akaike Information Criterion. For a sample of size n, k = log(n) corresponds to the Bayesian Information Criterion. As this factor is numeric, values corresponding to other IC may be used freely.

min.spec

optional integer value specifying the minimum final model size for forward selection. By default, forward selection will add species to the model until the value of the chosen IC ceases to improve. If this parameter is increased, forward selection will add the best available species up to the specified minimum model size before continuing with the default selection process.

starting.spec

optional character vector specifying the starting species for the forward selection algorithm. Where known, two or more species may be specified to ensure their inclusion in the final model, reducing computation times for the algorithm. The default is NULL.

silence

if true, additional information is printed. Default is false.

Details

The function uses a forward selection algorithm and the simplified MLE method to choose the prey species to be included in the model and then returns the diet estimates corresponding to these species.

Value

A list with components:

Diet_Estimates

A matrix of the diet estimates for each predator where each row corresponds to a predator and each column to a prey species. The estimates are expressed as proportions summing to one.

Selection_Order

A data frame summarizing each step of the algorithm, giving the order of species selection and the corresponding IC values.

Selection_Tables

A list containing a data frame for each step of the selection process, providing the IC values associated with adding any one candidate species at that step.

See Also

backward.elimination()

Examples


 ## This example takes some time to run.
 ## Please uncomment code below to run.

#library(dplyr)
#library(compositions)
## Package data: FAs
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Package data: Prey
#data(preyFAs)
#prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]
#prey.sub=prey.sub/apply(prey.sub,1,sum)
#group=as.vector(preyFAs$Species)
#prey.sub = cbind(group,prey.sub)
#sort.preytype <- order(prey.sub[, 1])
#prey.matrix <- prey.sub[sort.preytype,]

## Package data: Predators
#data(predatorFAs)
#tombstone.info = predatorFAs[,1:4]
#predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
#npredators = nrow(predator.matrix)

## Package data: Fat content
#FC = preyFAs[,c(2,3)]
#FC = as.vector(tapply(FC$lipid,FC$Species,mean,na.rm=TRUE))

## Package data: Calibration coefficients
#data(CC)
#cal.vec = CC[,2]
#cal.mat = replicate(npredators, cal.vec)
#rownames(cal.mat) <- CC$FA
#names(cal.vec) <- rownames(cal.mat)

## QFASA (KL)
#sample.qfasa <- p.QFASA(predator.matrix,MEANmeth(prey.matrix),cal.mat,
#dist.meas = 1,gamma=1,FC,
#start.val = rep(1,nrow(MEANmeth(prey.matrix))),fa.set)

## Forward Selection
#sample.fs <- forward.selection(predator.matrix,prey.matrix,cal.vec,FC,fa.set,
#min.spec = 5,starting.spec = c("capelin", "herring"))
## Output
#fs.estimates <- sample.fs$`Diet Estimates`

Generate pseudo predators with ith predator having true diet given by ith row of diet.null.mat.

Description

Generate pseudo predators with ith predator having true diet given by ith row of diet.null.mat.

Usage

gen.pseudo.seals(prey.mat, diet.null.mat, cal.mat, fat.cont, noise, nprey)

Arguments

prey.mat

matrix containing a representative FA signature from each prey group (usually the mean). The first column must index the prey group.

diet.null.mat

null diet

cal.mat

matrix of calibration coefficients where the i th column is to be used with the i th predator.

fat.cont

vector of fat content

noise

proportion of noise to add to the simulation.

nprey

number of prey to sample.


Get simplified MLE estimates

Description

Get simplified MLE estimates

Usage

likelihoodEstimates(pred.mat, prey.mat, cal.mat, fat.vec, ext.fa)

Returns the geometric mean of a compositional vector

Description

Returns the geometric mean of a compositional vector

Usage

mean_geometric(x)

Arguments

x

compositional vector


Modifies the zeros for a single FA signature using the multiplicative replacement method (and same delta for every zero).

Description

Modifies the zeros for a single FA signature using the multiplicative replacement method (and same delta for every zero).

Usage

mod.zeros.FA.sig(y, delta)

Modifies the zeros for a sample of FA signatures using the multiplicative replacement method (and same delta for every zero).

Description

Modifies the zeros for a sample of FA signatures using the multiplicative replacement method (and same delta for every zero).

Usage

mod.zeros.FA.sig.mat(y.mat, delta)

Multiplicative replacement of zeroes

Description

Multiplicative replacement of zeroes

Usage

multiplicativeReplacement(compositional.mat, delta = 1e-05)

Arguments

compositional.mat

matrix containing compositional data (for example, FA signatures) that may contain zeros.

delta

imputed value

Value

The compositional matrix with zeros modified.


Find simultaneous confidence intervals for diet proportions of a single prey species i.e. solve f(pio) = PVAL(pio) = alpha1. Calls root finding function root.beta.

Description

Find simultaneous confidence intervals for diet proportions of a single prey species i.e. solve f(pio) = PVAL(pio) = alpha1. Calls root finding function root.beta.

Usage

opt.beta.lim(alpha1, par.list, R, p.mat, k)

Arguments

alpha1

simultaneous confidence level

par.list

a list of R.p lists of I beta distribution parameters phi and theta that define diet proportion estimates for each of the prey species. Effectively R.p beta distributions for each of the I prey species from which we bootstrap to calculate p-values.

R

number of bootstrap replicates to use in p-value estimation.

p.mat

predator diet estimates.

k

prey species index 1...I

Value

upper and lower limits simultaneous intervals respectively.


Returns simplified MLE diet estimates corresponding to a sample of predators.

Description

Computes the diet estimate for each predator in pred.mat using the simplified MLE method, without the use of random effects.

Usage

p.MLE(pred.mat, prey.mat, cal.mat, FC, ext.fa)

Arguments

pred.mat

matrix containing the FA signatures of the predators.

prey.mat

matrix containing the FA signatures of the individual prey. The first column must index the prey group. prey.mat is the prey database.

cal.mat

matrix of calibration factors where the i th column is to be used with the i th predator. If modelling is to be done without calibration coefficients, simply pass a vector or matrix of ones.

FC

vector of fat content of length equal to the number of prey groups or species.

ext.fa

subset of fatty acids to be used to obtain diet estimates.

Details

The assumed model is similar to the MUFASA model but the random effects are replaced by the prey species' sample means to speed up computations. Unlike p.MUFASA, this function does not require integration and hence is much faster.

Value

A list with components:

Diet_Estimates

A matrix of the diet estimates for each predator where each row corresponds to a predator and the columns to prey species. The estimates are expressed as proportions summing to one.

Var_Epsilon

Optimized values of error variance. See reference.

nll

Negative log likelihood values. As per solnp documentation, nll is a "vector of function values during optimization with last one the value at the optimal".

References

Steeves, Holly (2020) Maximum likelihood approach to diet estimation and inference based on fatty acid signatures. PhD thesis available at https://dalspace.library.dal.ca/handle/10222/80034.

Examples


##  This example takes some time to run.
## Please uncomment the code below to run.


#library(dplyr)
#library(compositions)


## Fatty Acids
#data(FAset)
#ext.fa <- as.vector(unlist(FAset))

## Predators
#data(predatorFAs)
#pred.mat <- predatorFAs[, -c(1:4)]
#n.pred <- nrow(pred.mat)

## Prey
#data(preyFAs)
#prey.mat <- preyFAs[, -c(1,3)]

#FC = preyFAs[,c(2,3)]
#FC = as.vector(tapply(FC$lipid,FC$Species,mean,na.rm=TRUE))

## Calibration Coefficients
#data(CC)
#cal.vec = CC[,2]
#cal.mat = replicate(n.pred, cal.vec)
#rownames(cal.mat) <- CC$FA


## Diet Estimates
#mle.est <- p.MLE(pred.mat, prey.mat, cal.mat, FC, ext.fa)
#mle.est$"Diet Estimates"

Returns MUFASA diet estimates corresponding to a sample of predators.

Description

Computes the diet estimate for each predator in pred.mat using MLE method.

Usage

p.MUFASA(pred.mat, prey.mat, cal.mat, FC, ext.fa)

Arguments

pred.mat

matrix containing the FA signatures of the predators.

prey.mat

matrix containing FA signatures from each prey group The first column must index the prey group. prey.mat is the prey database.

cal.mat

matrix of calibration factors where the i th column is to be used with the i th predator. If modelling is to be done without calibration coefficients, simply pass a vector or matrix of ones. cal.mat must contain names of FAs.

FC

vector of fat content of length equal to the number of prey groups or species.

ext.fa

subset of fatty acids to be used to obtain QFASA diet estimates.

Value

A list with components:

Diet_Estimates

A matrix of the diet estimates for each predator where each row corresponds to a predator and the columns to prey species. The estimates are expressed as proportions summing to one.

nll

Negative log likelihood values. As per solnp documentation, nll is "Vector of function values during optimization with last one the value at the optimal".

Var_Epsilon

Optimized values of error variance. See reference.

References

Steeves, Holly (2020) Maximum likelihood approach to diet estimation and inference based on fatty acid signatures. PhD thesis available at https://dalspace.library.dal.ca/handle/10222/80034.

See Also

p.MLE() for a simplifed version of p.MUFASA() that is faster to run.

Examples


 ## This example takes some time to run.
 ## Please uncomment code below to run.

#library(dplyr)
#library(compositions)
 ## Fatty Acids
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Predators
#data(predatorFAs)
#tombstone.info = predatorFAs[,1:4]
#predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
#npredators = nrow(predator.matrix)

## Prey
## Extracting a small number of species to speed up calculations for the example.
#data(preyFAs)
#prey.matrix = preyFAs[,-c(1,3)]
#spec.red <-c("capelin", "herring", "mackerel", "pilchard", "sandlance")
#spec.red <- sort(spec.red)
#prey.red <- prey.matrix %>% filter(Species %in% spec.red)

## Fat content
#FC = preyFAs[,c(2,3)]
#FC = FC %>%  arrange(Species)
#FC.vec = tapply(FC$lipid,FC$Species,mean,na.rm=TRUE)
#FC.red <- FC.vec[spec.red]

## Calibration Coefficients
#data(CC)
#cal.vec = CC[,2]
#cal.m = replicate(npredators, cal.vec)
#rownames(cal.m) <- CC$FA

#M <- p.MUFASA(predator.matrix, prey.red, cal.m, FC.red, fa.set)

## Diet EStimates

#M$Diet_Estimates


Returns QFASA diet estimates corresponding to a sample of predators.

Description

Computes the diet estimate for each predator in predator.mat using either the Kullback-Leibler Distance (KL), the Aitchison Distance (AIT) or the Chi-Square Distance (CS).

Usage

p.QFASA(
  predator.mat,
  prey.mat,
  cal.mat,
  dist.meas,
  gamma = 1,
  FC = rep(1, nrow(prey.mat)),
  start.val = rep(0.99999, nrow(prey.mat)),
  ext.fa
)

Arguments

predator.mat

matrix containing the FA signatures of the predators.

prey.mat

matrix containing a representative FA signature from each prey group (usually the mean). The first column must index the prey group. Note can use function MEANmeth to calculate the means.

cal.mat

matrix of calibration factors where the i th column is to be used with the i th predator. If modelling is to be done without calibration coefficients, simply pass a vector or matrix of ones.

dist.meas

distance measure to use for estimation: 1=KL, 2=AIT or 3=CS

gamma

parameter required for calculations using CS distance (passed to CS.obj). Currently being set to 1.

FC

vector of fat content of length equal to the number of prey groups or species.

start.val

initial vector of parameters to be optimized

ext.fa

subset of fatty acids to be used to obtain QFASA diet estimates.

Details

Before carrying out an analysis using QFASA, rows of prey database must be normalized to sum to one. See Example for code that extracts a subset of FAs and then normalizes the prey database signatures.

Value

A list with components:

Diet Estimates

A matrix of the diet estimates for each predator where each row corresponds to a predator and the columns to prey species. The estimates are expressed as proportions summing to one.

Additional Measures

For each predator for which a diet estimate was obtained:

ModFAS

the value of the modelled fatty acid. These are expressed as proportions summing to one.

DistCont

The contribution of each fatty acid to the final minimized distance.

PropDistCont

The contribution of each fatty acid to the final minimized distance as a proportion of the total.

MinDist

The final minimized distance.

References

Iverson, Sara J., Field, Chris, Bowen, W. Don and Blanchard, Wade (2004) Quantitative Fatty Acid Signature Analysis: A New Method of Estimating Predator Diets. Ecological Monographs, 74(2), 211-235

Examples

 ## Fatty Acids
 data(FAset)
 fa.set = as.vector(unlist(FAset))

 ## Predators
 data(predatorFAs)
 tombstone.info = predatorFAs[,1:4]
 predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
 npredators = nrow(predator.matrix)

 ## Prey
 data(preyFAs)
 prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]
 prey.sub=prey.sub/apply(prey.sub,1,sum)
 group=as.vector(preyFAs$Species)
 prey.matrix=cbind(group,prey.sub)
 prey.matrix=MEANmeth(prey.matrix)

 ## Fat Content

 FC = preyFAs[,c(2,3)]
 FC = as.vector(tapply(FC$lipid,FC$Species,mean,na.rm=TRUE))

 ## Calibration Coefficients
 data(CC)
 cal.vec = CC[,2]
 cal.mat = replicate(npredators, cal.vec)

 ## Run QFASA
 Q = p.QFASA(predator.matrix,
             prey.matrix,
             cal.mat,
             dist.meas = 1,
             gamma=1,
             FC,
             start.val = rep(1,nrow(prey.matrix)),
             fa.set)

## Diet Estimates
DietEst = Q$'Diet Estimates'


Simultaneous maximum unified fatty acid signature analysis

Description

Returns SMUFASA calibration coefficient estimates and an average diet among a sample of predators.

Usage

p.SMUFASA(pred.mat, prey.mat, FC, ext.fa)

Arguments

pred.mat

matrix containing the FA signatures of the predators.

prey.mat

matrix containing FA signatures from each prey group. The first column must index the prey group. prey.mat is the prey database.

FC

vector of fat content of length equal to the number of prey groups or species.

ext.fa

subset of fatty acids to be used to obtain estimates.

Details

Calibration coefficients (CCs) are not supplied but are instead estimated. While one overall diet is computed, the CCs can be used in p.QFASA or p.MUFASA to estimate individual diet estimates.

Value

A list with components:

Cal_Estimates

A vector of estimated calibration coefficients common to all predators. The k th value corresponds to the k th fatty acid. The estimates sum to the number of fatty acids.

Diet_Estimate

A vector of estimates of the average diet among the predators. The estimates are expressed as proportions summing to one.

Var_Epsilon

Optimized values of error variance.

nll

Negative log likelihood values. As per solnp documentation, nll is "Vector of function values during optimization with last one the value at the optimal".

Examples

## This example takes some time to run.
## Please uncomment code below to run.

#library(dplyr)
#library(compositions)
## Fatty Acids
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Predators
#data(predatorFAs)
#tombstone.info = predatorFAs[,1:4]
#predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
#npredators = nrow(predator.matrix)

## Prey
## Extracting a small number of species to speed up calculations for the example.
#data(preyFAs)
#prey.matrix = preyFAs[,-c(1,3)]
#spec.red <-c("capelin", "herring", "mackerel", "pilchard", "sandlance")
#spec.red <- sort(spec.red)
#prey.red <- prey.matrix %>% filter(Species %in% spec.red)

## Fat content
#FC = preyFAs[,c(2,3)]
#FC = FC %>%  arrange(Species)
#FC.vec = tapply(FC$lipid,FC$Species,mean,na.rm=TRUE)
#FC.red <- FC.vec[spec.red]

#out <- p.SMUFASA(predator.matrix, prey.red, FC.red, fa.set)

#out$Cal_Estimates


Bootstrap statistic function: in this case it is the mean (meanBEZI) of the fitted (gamlss) ZIB distribution.

Description

Bootstrap statistic function: in this case it is the mean (meanBEZI) of the fitted (gamlss) ZIB distribution.

Usage

p.beta(data)

Arguments

data

data

Value

the expected value of the response for a fitted model


Simultaneous estimation of diet composition and calibration coefficients

Description

Computes the diet estimate for each predator in pred.sig as well as an overall estimate of the calibration coefficient vector.

Usage

p.sim.QFASA(pred.sig, prey.mat, FC = rep(1, nrow(prey.mat)))

Arguments

pred.sig

matrix containing the FA signatures of the predator

prey.mat

matrix containing a representative FA signature from each prey group (usually the mean). The first column must index the prey group.

FC

vector of fat content of length equal to the number of prey groups (or species)

Details

Starting values for the diet estimates are equal proportions and a vector of ones is used for the calibration coefficients.

Value

A list with components:

diet.est

A matrix of the diet estimates for each predator where each row corresponds to a predator and the columns to prey species. The estimates are expressed as proportions summing to one.

cc.est

Estimated vector of calibration coefficients

References

Bromaghin, Jeffrey F., Budge, Suzanne M., Thiemann, Gregory and Rode, Karyn D. (2017) Simultaneous estimation of the diet composition and calibration coefficients with fatty acid signature data. Ecology and Evolution, 7(16), 6103-6113

Examples


##  This example takes some time to run.
## Please uncomment code below to run.

## Fatty Acids
#data(FAset)
#fa.set = as.vector(unlist(FAset))

## Predators
#data(predatorFAs)
#tombstone.info = predatorFAs[,1:4]
#predator.matrix = predatorFAs[,5:(ncol(predatorFAs))]
#npredators = nrow(predator.matrix)

## Need predator and prey to have same length

#predator.ext <- predator.matrix[fa.set]
#predator.ext <- predator.ext/rowSums(predator.ext)

## Prey
#data(preyFAs)
#prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]
#prey.sub=prey.sub/apply(prey.sub,1,sum)
#group=as.vector(preyFAs$Species)
#prey.matrix=cbind(group,prey.sub)
#prey.matrix=MEANmeth(prey.matrix)

## Fat Content
#FC = preyFAs[,c(2,3)]
#FC = as.vector(tapply(FC$lipid,FC$Species,mean,na.rm=TRUE))

#Q.sim <-p.sim.QFASA(predator.ext,prey.matrix,FC)
## Average Diet Estimate
#round(colMeans(Q.sim[[1]]),3)
## Calibration Coefficients
#Q.sim[[2]]

Predator fatty acid signatures. Each predator signature is a row with fatty acid proportions in columns.

Description

Fatty acid signatures are subsetted for the chosen fatty acid set and renormalized during the modelling so there is no need to subset and/or renormalize prior to running p.QFASA. However, make sure that the the same fatty acids appear in the predator and prey files (if a FA appears in one but not the other the code will give you an error).

Usage

predatorFAs

Format

A data frame with 10 observations and 70 variables:

SampleCode

TODO

AnimalCode

TODO

SampleGroup

TODO

Biopsy

TODO

c12.0
c13.0
Iso14
c14.0
c14.1w9
c14.1w7
c14.1w5
Iso15
Anti15
c15.0
c15.1w8
c15.1w6
Iso16
c16.0
c16.1w11
c16.1w9
c16.1w7
c7Mec16.0
c16.1w5
c16.2w6
Iso17
c16.2w4
c16.3w6
c17.0
c16.3w4
c17.1
c16.4w3
c16.4w1
c18.0
c18.1w13
c18.1w11
c18.1w9
c18.1w7
c18.1w5
c18.2d5.11
c18.2w7
c18.2w6
c18.2w4
c18.3w6
c18.3w4
c18.3w3
c18.3w1
c18.4w3
c18.4w1
c20.0
c20.1w11
c20.1w9
c20.1w7
c20.2w9
c20.2w6
c20.3w6
c20.4w6
c20.3w3
c20.4w3
c20.5w3
c22.1w11
c22.1w9
c22.1w7
c22.2w6
c21.5w3
c22.4w6
c22.5w6
c22.4w3
c22.5w3
c22.6w3
c24.1w9

Details

Unlike the original QFASApack code the predator data can contain as much tombstone data in columns as you wish but the predator FA signatures must be extracted as a separate input in order to run in p.QFASA.


Produces a dendrogram using distances between the mean FA signatures of the prey types.

Description

Performs a hierarchical cluster analysis of mean prey fatty acid signatures using function hclust.

Usage

prey.cluster(prey.fa, method = "complete", dist.meas = 2)

Arguments

prey.fa

data frame of prey fatty acid signature samples. First column must be species used to group samples. Other columns are assumed to be fatty acid proportions.

method

the agglomeration method to be used. This should be one of the possible methods in hclust such as "single", "complete" or "average". Default is "complete".

dist.meas

distance measure to use for calculating dissimilarities: 1=KL, 2=AIT or 3=CS. Default is AIT.

Value

Plot (dendrogram)

Examples


## Fatty Acids
data(FAset)
fa.set = as.vector(unlist(FAset))

## prey.cluster requires full prey database.
data(preyFAs)
prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]
prey.sub=prey.sub/apply(prey.sub,1,sum)
group=as.vector(preyFAs$Species)
prey.matrix=cbind(group,prey.sub)

prey.cluster(prey.matrix,method="average",dist.meas=3)

Each prey fatty acid signature is systematically removed from the supplied prey database and its QFASA diet estimate is obtained by treating the individual as a predator.

Description

Each prey fatty acid signature is systematically removed from the supplied prey database and its QFASA diet estimate is obtained by treating the individual as a predator.

Usage

prey.on.prey(preybase, dist.meas, gamma = 1)

Arguments

preybase

first column is name of species and remaining columns are fatty acids.

dist.meas

see help file for p.QFASA.

gamma

see help file for p.QFASA.

Value

diet estimate

Examples

data(preyFAs)
my.preybase <- preyFAs[, -c(1,3)]

# Note: uncomment examples to run. CRAN tests fail because execution time > 5 seconds
# diets.out <- prey.on.prey(my.preybase, 2)
# round(MEANmeth(diets.out), 3)
     

Prey fatty acid signatures. Each prey signature is a row with fatty acid proportions in columns.

Description

The prey file should contain all of the individual fatty acid signatures of the prey and their lipid contents (where appropriate) - a matrix of the mean values for the FAs (prey.matrix) by the designated prey modelling group is then calculated using the MEANmeth function.

Usage

preyFAs

Format

A data frame with 302 observations and 70 variables:

Lab.Code

TODO

Species

TODO

lipid

TODO

c12.0
c13.0
Iso14
c14.0
c14.1w9
c14.1w7
c14.1w5
Iso15
Anti15
c15.0
c15.1w8
c15.1w6
Iso16
c16.0
c16.1w11
c16.1w9
c16.1w7
c7Me16.0
c16.1w5
c16.2w6
Iso17
c16.2w4
c16.3w6
c17.0
c16.3w4
c17.1
c16.3w1
c16.4w3
c16.4w1
c18.0
c18.1w13
c18.1w11
c18.1w9
c18.1w7
c18.1w5
c18.2d5.11
c18.2w7
c18.2w6
c18.2w4
c18.3w6
c18.3w4
c18.3w3
c18.3w1
c18.4w3
c18.4w1
c20.0
c20.1w11
c20.1w9
c20.1w7
c20.2w9
c20.2w6
c20.3w6
c20.4w6
c20.3w3
c20.4w3
c20.5w3
c22.1w11
c22.1w9
c22.1w7
c22.2w6
c21.5w3
c22.4w6
c22.5w6
c22.4w3
c22.5w3
c22.6w3
c24.1w9

Details

Like the predator .csv file you can have as many tombstone data columns as required but there must be at least one column that identifies the modelling group, in this case, Species.

Unlike the predator data, the prey data is not subsetted and renomalized during the modelling so the prey file needs to be subsetted for the desired fatty acid set and renormalized to sum to 1 prior to calculating the mean values.

The full FA set is extracted from the data frame (columns 4 onward), subsetted for the FA set in use and then renormalized over 1. The modelling group names (the "Species" column in this case) is then added back to the subsetted and renormalized data (as the first column) and the average values calculated using the MEANmeth function. Note that for the MEANmeth function to work the modelling group name must be in the first column.


Generate a pseudo predator by sampling with replacement from prey database.

Description

Generates a single pseudo predator by sampling with replacement from prey database. To generate a sample of pseudo predators, please refer to example code.

Usage

pseudo.pred(diet, preybase, cal.vec, fat.vec, preysize = 2)

Arguments

diet

the "true" or "desired" diet of the pseudo predator with prey species in alphabetical order (i.e.in the order of table(preyFAs[,2])). A compositional vector of proportions that sums to one with length equal to the number of prey species.

preybase

prey database from which to generate the pseudo predator. First column must provide the species name.

cal.vec

vector of calibration coefficients whose length is the same as the number of fatty acids in prey database.

fat.vec

vector of fat content whose length is the same as the number of species.

preysize

number of prey to sample from prey database. If preysize=1, then one prey is selected from each species. Otherwise, a sample of n_k signatures (where n_k is sample size for species k) is obtained by sampling with replacement.

Details

The default is to re-sample all of the prey signatures within each species (that is, preysize=2). Alternatively, one prey may be randomly selected from each species yielding potentially more variable pseudo-predators. For details on simulating realistic predators signatures, see Bromaghin, J. (2015) Simulating realistic predator signatures in quantitative fatty acid signature analysis, Ecological Informatics, 30, 68-71.

Value

A simulated predator FA signature.

Examples

data(preyFAs)

# Generating a sample of 10 pseudo predators each with "true" diet being
# (1/11,1/11,...1/11), no calibration effect and no fat content.  The QFASA diet estimate
# is then computed for each pseudo predator.

# Note: To incorporate calibration and fat content in a simulation study,
# one set of calibration and fat content is generally used to simulate the pseudo predator
# and another is used to estimate the diet.

set.seed(11)
p.mat <- matrix(rep(NA,10*11),nrow=10)
for (i in 1: 10) {
    my.seal <- pseudo.pred(rep(1/11,11),
                            preyFAs[,-c(1,3)],
                            rep(1,ncol(preyFAs[,-c(1,3)])-1),
                            rep(1,11))
     p.mat[i,] <- p.QFASA(my.seal,
                          MEANmeth(preyFAs[,-c(1,3)]),
                          rep(1,length(my.seal)),
                          2,
                          ext.fa=colnames(preyFAs[,-c(1:3)]))$`Diet Estimates`
 }

# Can verify that average diet estimate of the 10 pseudo predators is close to
# "true" diet.

 colnames(p.mat) <- as.vector(rownames(MEANmeth(preyFAs[,-c(1,3)])))
 round(apply(p.mat,2,mean),3)


Generate a pseudo predator parametrically from multivariate normal distributions.

Description

Generate a pseudo predator parametrically from multivariate normal distributions.

Usage

pseudo.pred.norm(mu.mat, sigma.pool, diet)

Arguments

mu.mat

matrix where each row represents the mean transformed FA signature of each prey type

sigma.pool

pooled variance-covariance matrix of the transformed fatty acid signatures of prey types

diet

the "true" or "desired" diet of the pseudo predator with prey species in the same order as the rows of mu.mat. A compositional vector of proportions that sums to one with length equal to the number of prey species.

Details

Similar to pseudo.pred but instead generates the pseudo-predators parametrically by assuming ilr transformed FA signatures have a multivariate normal distribution.

Value

A simulated predator FA signature. See pseudo.pred for an example illustrating how to generate a sample of pseudo predators.


FUNCTION TO GENERATE ns PSEUDO SEALS WHERE ns IS THE NUMBER OF ROWS IN diet.mat.seal AND RETURNS THE CORRESPONDING QFASA DIET ESTIMATES. ASSUMES EACH ROW IS A DIET VECTOR AND EACH COLUMN CORRESPONDS TO 1 PREY SPECIES IN THE DIET

Description

FUNCTION TO GENERATE ns PSEUDO SEALS WHERE ns IS THE NUMBER OF ROWS IN diet.mat.seal AND RETURNS THE CORRESPONDING QFASA DIET ESTIMATES. ASSUMES EACH ROW IS A DIET VECTOR AND EACH COLUMN CORRESPONDS TO 1 PREY SPECIES IN THE DIET

Usage

pseudo.pred.rep(
  diet.mat.seal,
  prey.database,
  fatcont.mat,
  dist.meas,
  ext.fa,
  gamma = 1
)

FUNCTION TO GENERATE ns SEALS FOR EACH OF ny YEARS

Description

FUNCTION TO GENERATE ns SEALS FOR EACH OF ny YEARS

Usage

pseudo.pred.table(
  diet.rep.mat,
  prey.database,
  fatcont.mat,
  dist.meas,
  ext.fa,
  gamma = 1
)

Generate a single pseudo predator FA signature

Description

THIS IS THE NEW pseudo.seal FUNCTION THAT ALLOWS 1) FAT CONTENT TO BE INCLUDED IN THE GENERATED SEALS AND 2) SOME SPECIES TO BE TRULY ZERO (THAT IS,"ZERO SPECIES" DO NOT HAVE TO BE INCLUDED IN THE "NOISE" ) NOTE: IT IS ASSUMED THAT SUM(DIET) IS 1-NOISE

THIS IS THE NEW pseudo.seal FUNCTION THAT ALLOWS 1) FAT CONTENT TO BE INCLUDED IN THE GENERATED SEALS AND 2) SOME SPECIES TO BE TRULY ZERO (THAT IS,"ZERO SPECIES" DO NOT HAVE TO BE INCLUDED IN THE "NOISE" ) NOTE: IT IS ASSUMED THAT SUM(DIET) IS 1-NOISE

Usage

pseudo.seal(prey.sim, diet, noise, nprey, cal, fat.cont, specify.noise)

pseudo.seal(prey.sim, diet, noise, nprey, cal, fat.cont, specify.noise)

Arguments

prey.sim

OUTPUT OF split.prey

diet

DIET COMPOSITION VECTOR (NOTE: THIS VECTOR SHOULD SUM TO 1-NOISE. THE NOISE WILL BE ADDED TO THE diet VECTOR.)

noise

AMOUNT OF NOISE

nprey

nprey TOTAL NUMBER OF PREY TO BE SAMPLED

cal

CALIBRATION FACTORS

fat.cont

VECTOR OF FAT CONTENT OF LENGTH=I (# OF SPECIES)

specify.noise

A BOOLEAN VECTOR WITH TRUES DENOTING SPECIES TO USE IN NOISE.

Value

seal.star SIMULATED SEAL FA SIGNATURE.

seal.star SIMULATED SEAL FA SIGNATURE.


RETURNS RHO AND THE BOOTSTRAP SAMPLE DETERMINED BY ind.

Description

RETURNS RHO AND THE BOOTSTRAP SAMPLE DETERMINED BY ind.

Usage

rho.boot.fun(ind, data, gamma.rho)

FUNCTION TO BE PASSED TO bootstrap::jackknife.

Description

FUNCTION TO BE PASSED TO bootstrap::jackknife.

Usage

rho.jack.fun(ind, data, gamma.rho)

Find root (i.e. solve f(pio) = PVAL(pio) = alpha1 using either uniroot or optimize.

Description

Find root (i.e. solve f(pio) = PVAL(pio) = alpha1 using either uniroot or optimize.

Usage

root.beta(x1, x2, alpha, par.list, R, p.mat, k, low = TRUE)

Arguments

x1

lower starting value

x2

upper starting value

alpha

simultaneous confidence level

par.list

parameters needed to compute p-value by bootstrapping

R

number of bootstraps

p.mat

predator diet estimates

k

prey species index 1...I

low

TRUE if computing lower interval.

Value

root which will be lower or upper CI limit


Splits prey database into a simulation set (1/3) and a modelling set (2/3). Returns a list:

Description

1. simulation prey database 2. modelling prey database

1. simulation prey database 2. modelling prey database

Usage

split_prey(prey.mat)

split_prey(prey.mat)

Arguments

prey.mat

matrix of individual prey fatty acid signatures where the first column denotes the prey type

Details

IF number of samples of a prey type <=5, then prey.mod AND prey.sim are duplicated instead of split.

IF number of samples of a prey type <=5, then prey.mod AND prey.sim are duplicated instead of split.


Called by testfordiff.ind.pval().

Description

Called by testfordiff.ind.pval().

Usage

testfordiff.ind.boot(data, ns1, R)

Arguments

data

sample of compositional data

ns1

sample size of compdata.1

R

number of bootstrap samples. default is 500.


Called by testfordiff.ind.boot().

Description

Called by testfordiff.ind.boot().

Usage

testfordiff.ind.boot.fun(data, i, ns1, change.zero = 1e-05)

Arguments

data

sample of compositional data

i

row index

ns1

sample size of compdata.1

change.zero

tolerance


Test for a difference between two independent samples of compositional data. Zeros of any type are allowed.

Description

Test for a difference between two independent samples of compositional data. Zeros of any type are allowed.

Usage

testfordiff.ind.pval(compdata.1, compdata.2, R = 500)

Arguments

compdata.1

sample of compositional data.

compdata.2

sample of compositional data.

R

number of bootstrap samples, default is 500.

Value

p-value obtained through a multivariate permutation test with test statistic based on chi-square distances.

References

Stewart, C., Iverson, S. and Field, C. (2014) Testing for a change in diet using fatty acid signatures. Environmental and Ecological Statistics 21, pp. 775-792.

Examples


## Prey
data(preyFAs)

## Capelin FA sig
capelin.sig=preyFAs[preyFAs$Species=="capelin",4:(ncol(preyFAs))]
capelin.sig=capelin.sig/apply(capelin.sig,1,sum)

## Sandlance FA sig
sandlance.sig=preyFAs[preyFAs$Species=="sandlance",4:(ncol(preyFAs))]
sandlance.sig=sandlance.sig/apply(sandlance.sig,1,sum)

# Note:
# # Uncomment examples to run. CRAN tests fail because execution time > 5 seconds
# testfordiff.ind.pval(as.matrix(capelin.sig),as.matrix(sandlance.sig))



Measure of (unadjusted) repeatability

Description

Measure of (unadjusted) repeatability

Usage

two.factor.rep(dataset, gamma = 1)

Arguments

dataset

data frame of diet estimates. Columns 1 and 2 of dataset must be the first and second factors in your two factor ANOVA model where column 1 specifies the predator and column 2 the year, season, etc...

gamma

needed to compute CS distance. Default is 1.

Details

We use absolute repeatability (or intraclass correlation coefficient). The difference in the two types is discussed in: McGraw and Wong (1996) Forming Inferences about some intraclass correlation coefficients. Psychological Methods. 1(1):30-46.

Value

unadjusted consistent repeatability, unadjusted absolute repeatability and the number of levels of second factor (eg. year, seasons, etc..)


Sample example of unbalanced repeatability diet estimates data with a max of two repeated measurements per predator.

Description

Sample example of unbalanced repeatability diet estimates data with a max of two repeated measurements per predator.

Usage

unbal.diet.data

Format

A data frame with 96 predator diets (50 unique predators) and 13 variables:

Seal.ID

Predator (1 to 50)

Year

Either 1 or 2

capelin

estimated diet proportion

coho

estimated diet proportion

eulachon

estimated diet proportion

herring

estimated diet proportion

mackerel

estimated diet proportion

pilchard

estimated diet proportion

pollock

estimated diet proportion

sandlance

estimated diet proportion

squid

estimated diet proportion

surfsmelt_s

estimated diet proportion

sufsmelt_lg

estimated diet proportion


Measure of Repeatability for Diet Estimates (Unbalanced/Missing Value Case)

Description

Computes a measure of repeatability for a sample of predators with repeated diet estimate measurements (Unbalanced/Missing Value Case)

Usage

unbal.rep.CI(
  data,
  B,
  R,
  CI = TRUE,
  alpha,
  prey.database,
  fatcont.mat,
  dist.meas,
  ext.fa,
  gamma.QFASA = 1,
  gamma.rho = 1
)

Arguments

data

data frame of diet estimates. First column must denote the predator and second column the second factor (eg. year or season). Need not contain the same number of repeated measurements for each predator.

B

number of pseudo predators samples to generate for bias calculation. Default is set to 50 because is slow to run.

R

number of bootstrap samples (i.e. R samples for each generated sample of pseudo predators). Default is set to 100 because it is slow to run.

CI

indicates if a confidence interval for rho is to be calculated. Default is FALSE since this is time consuming to obtain.

alpha

a (1-alpha/2)X100 percent confidence interval is calculated for rho if CI=TRUE.

prey.database

prey data base that was used to compute the QFASA diet estimates in data. Will be used to generate pseudo predators.

fatcont.mat

data frame or matrix of length equal to the number of prey FA signatures in prey data base. First column is name of species and second column is lipid.

dist.meas

distance measure to use in p.QFASA.

ext.fa

subset of FAs to use.

gamma.QFASA

if dist.meas=3, gamma is required. Default is 1.

gamma.rho

value of gamma to be used to compute CS distance in repeatablity functions. Default is 1.

Value

Bias corrected measure of repeatability, estimate of the bias and (if CI=TRUE) a confidence interval for the true repeatability.


RETURNS RHO AND THE BOOTSTRAP SAMPLE DETERMINED BY ind.

Description

RETURNS RHO AND THE BOOTSTRAP SAMPLE DETERMINED BY ind.

Usage

unbal.rho.boot.fun(ind, data, gamma.rho)

FUNCTION TO BE PASSED TO bootstrap::jackknife.

Description

FUNCTION TO BE PASSED TO bootstrap::jackknife.

Usage

unbal.rho.jack.fun(ind, data, gamma.rho)

Measure of (unadjusted) repeatability with missing values

Description

Measure of (unadjusted) repeatability with missing values

Usage

unbal.two.factor.rep(dataset, k.est.meth = 1, gamma = 1)

Arguments

dataset

data frame of diet estimates. Columns 1 and 2 of dataset must be the first and second factors in your two factor ANOVA model where column 1 specifies the predator and column 2 the year, season, etc... Missing values are allowed.

k.est.meth

default is 1 (harmonic mean). See details below.

gamma

needed to compute CS distance. Default is 1.

Details

We use the modified measure of repeatability that uses an adjusted degrees of freedom and takes into account the estimate of k. When k.est.meth=1, the harmonic mean is used (see p. 212 from Biometry Fourth Edition by Sokal and Rohlf) and when k.est.meth=2,estimate is n_0 from Lessels and Boag (1987).

Value

unadjusted consistent repeatability, unadjusted absolute repeatability and a modified measure of repeatability.


Use uniroot() to find roots and compare with bisection outcome

Description

Use uniroot() to find roots and compare with bisection outcome

Usage

uniroot.beta(x1, x2, alpha, par.list, R, p.mat, k)

Reintroduce excluded species to diet estimates as forced zeroes

Description

Reintroduce excluded species to diet estimates as forced zeroes

Usage

zeroEstimates(estimates, prey.mat)