QFASA Workflow Example"

Load Package

library(QFASA)
library(plyr)

Modeling Inputs

Prior to starting make sure that:

Distance Measure

Choose from one of three distance measures:

1) KL (Kullback-Leibler) 2) AIT (Aitchison) 3) CSD (Chi-Squared)

dist.meas=1

Fatty Acid Set

data(FAset)
fa.set = as.vector(unlist(FAset))

Matrix of Predator FA signatures

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

# number of predator FA signatures this is used to create the matrix of CC values (see section 6 below)
npredators = nrow(predator.matrix)

Matrix of Prey FA signatures

#full file
data(preyFAs)

#extract prey FA only from data frame and subset them for the FA set designated above
prey.sub=(preyFAs[,4:(ncol(preyFAs))])[fa.set]

#renormalize over 1
prey.sub=prey.sub/apply(prey.sub,1,sum) 

#extract the modelling group names from the full file
group=as.vector(preyFAs$Species)

#add modelling group names to the subsetted and renormalized FAs
prey.matrix=cbind(group,prey.sub)

#create an average value for the FA signature for each designated modelling group
prey.matrix=MEANmeth(prey.matrix) 

Prey Lipid Content

#numbers are the column which identifies the modelling group, and the column which contains the lipid contents
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, gamma=1, FC, start.val=rep(1,nrow(prey.matrix)), fa.set)

p.QFASA Output

The QFASA output is a list with 2 components:

Diet Estimates

This is a matrix of the diet estimate for each predator (by rows, in the same order as the input file) by the modelling groups (by column, in the same order as the prey.matrix file). The estimates are expressed as a proportion (they will sum to 1). In the code below the Diet Estimate matrix is extracted from the QFASA output and the modelling group identities and predator tombstone data (created above) are added to the matrix:

DietEst = Q$'Diet Estimates'

#estimates changed from proportions to percentages
DietEst = round(DietEst*100,digits=2)
DietEst = cbind(tombstone.info,DietEst)

Additional Measures

This is a list of lists where each list (one per predator) is itself a list of four outputs:

Add.meas = ldply(Q$'Additional Measures', data.frame)

Note that the function "conf.meth" will return approximate simultaneous confidence intervals for diet.



Try the QFASA package in your browser

Any scripts or data that you put into this service are public.

QFASA documentation built on Sept. 11, 2024, 8:08 p.m.