tolerance: Tolerance

Description Usage Arguments Details Value Examples

View source: R/tolerance.r

Description

A function to calculate species response curves using various models. Get optimum value from taxon-environment relationship 1.WA, 2. cdf_Abundance 3. cdf_p/a. 4. ecdf weighted 5. Linear logistic 6. quadratic logistic 7. GAM 5~7 using full data range; 11. Count. 12. Raw quantiles Requires the "reshape", "mgcv", and "maps" libraries.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
tolerance(spdata, envdata, sp.siteid = "Sample.ID", species = "GENUS",
  covar = NULL, sp.abndid = "RA", env.siteid = "Sample.ID",
  xvar = "cond", cutoff = 20, cutoff2 = 10, region = "all",
  lim = "GAM", coord = NULL, mtype = 3, dense.N = 201,
  cast = TRUE, plot.pdf = F, add.map = F, statename = NULL,
  add.lab = F, add.abund = T,
  main = "Capture Probability of Macroinvertebrate Taxon Along Conductivity Gradient",
  mar = c(5, 4, 3, 4), xlabs = expression(paste("Conductivity (", mu,
  "S/cm)")), log.x = TRUE, plus = F, rounder = 0, taus = c(50, 95),
  nbin = 61, wd = getwd())

Arguments

spdata

Species data.

envdata

Environmental data.

sp.siteid

Species data frame column name for site/sample id; default = "Sample.ID"

species

Species data frame column name for taxa name; default = ""GENUS"

covar

covariance; default = NULL

sp.abndid

Species data frame column name for species abundance; default = "RA"

env.siteid

Environmental data frame column name for site/sample id. Default is "Sample.ID"

xvar

Environmental data frame column name for analyte used in analysis; default = "cond"

cutoff

cutoff 1; default = 20

cutoff2

cutoff 2; Min number of samples for taxa occurrence. Only those above cut off are plotted. default = 10

region

region. A folder will be created in the working directory (wd) for the region; default = "all"

lim

"GAM" or "CDF" ; default = "GAM" if lim == "GAM", add gam plot xc95 otherwise, add "CDF"

coord

Map coordinates of samples; c("LONG_DD", "LAT_DD"). Default is NULL.

mtype

1 linear, 2 quadratic 3 gam model for ploting purpose; default = 3.

dense.N

the number of areas to cut into in the calculation of area under the curve; default = 201.

cast

; default = TRUE,

plot.pdf

to decide if we want specise vs. env plots; default = F

add.map

boolean for if a map should be plotted. Requires statename coord; default = F

statename

State name (e.g., Maryland) used for map; default = NULL

add.lab

boolean for adding labels to map; default = F

add.abund

boolean for adding abundance to map; default = T.

main

= "Capture Probability of Macroinvertebrate Taxon Along Conductivity Gradient",

mar

Plot margins; default = c(5, 4, 3, 4)

xlabs

X-axis labels for plots; default = expression(paste("Conductivity ( ", mu, "S/cm)"))

log.x

Whether to log transform and plot data; default = TRUE. log.x to use log10 transformed data, plus to use log10(+1) transformed data, sqrt

plus

; Use with log.x=TRUE if want log10(+1) transformation. default = F

rounder

How many digits to round results; default = 0.

taus

determine the output the percentile of env variable; default = c(50,95)

nbin

number of bins; default = 61

wd

Working directory for saving files.

Details

Species data file can be long or wide format. If in long format use cast=TRUE to transform.

Cutoff2 will limit the analysis based on taxon occurrence across all sites. Only those above this values will have plots generated.

Cutoff is used for co-occurrence of taxa and the environmental variable. Taxa below this threshold will not have curves added to the plots.

Plots will be produced in a PDF and saved to the specified folder (region) based on user defined variables.

The output data frame will have the following fields. The variable 'taus' determines the quantiles for some calculations. With the default values of 50 and 95 the 50th and 95th fields are shown below.

* tnames = taxa names derived from input data frame spdata

* N = Number of samples where taxon and environmental variable co-occur. samplen

* min_ob = minimum observation of environmental variable where taxon occurs. limits.

* X50_th_ob = 50th quantile observation of environmental variable where taxon occurs. limits.

* X95_th_ob = 95th quantile observation of environmental variable where taxon occurs. limits.

* max_ob = minimum observation of environmental variable where taxon occurs. limits.

* Opt_WA = Results model 1, weighted averaging, WA

* Tol_WA = Results model 1, weighted averaging, tol

* CDF_50_th_Abund and CDF_95_th_Abund= Results model 2, cdf_Abundance, df1[ic1,xvar]

* CDF_50_th_PA and CDF_95_th_PA= Results model 3, cdf_p/a, df1[ic2,xvar]

* CDF_wt_50_th and CDF_wt_95_th = Results model 4, ecdf weighted, eout

* LRM_50_th and LRM_95_th= Results model 5, linear logistic, lrm1.95f

* QLRM_50_th and QLRM_95_th = Results model 6, quadratic logistic, lrm2.95f

* Opt_qlrm = Results model 6, quadratic logistic, lrm2.opt

* Tol_qlrm = Results model 6, quadratic logistic, lrm2.tol

* GAM_50_th and GAM_95_th = Results model 7, GAM, lrm3.95f

* ROC = Summarizes all comparisons to compute area under ROC, roc

Value

Returns a data frame (cond.opt) and generates a PDF (results.taxon.gam.pdf) of plots (within the working directory in a subfolder for the region).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
region = "results"
env.cond <- tol.env.cond
ss <- tol.ss
condunit <- expression(paste("Conductivity ( ", mu, "S/cm)", sep = ""))
cond.opt <- tolerance(spdata = ss, envdata = env.cond,  sp.siteid = "NewSampID", species = "Genus", covar=NULL,
                      sp.abndid = "RA", env.siteid = "NewSampID", xvar = "cond", cutoff = 25, cutoff2 = 10,
                      region = "results", lim ="GAM", coord = NULL, mtype = 3, dense.N = 201, cast = FALSE,
                      plot.pdf = T, add.map = F, statename = NULL,  add.lab = F, add.abund=T,
                      main = "Capture Probability of Macroinvertebrate Taxon Along Conductivity Gradient",
                      mar = c(5,4,3,4), xlabs = condunit, log.x = T,
                      plus = F, rounder = 3, taus = c(50,95), nbin = 61, wd=getwd())
# view returned data frame
View(cond.opt)
# open saved PDF
system(paste0('open "',file.path(getwd(),region,"results.taxon.gam.pdf"),'"'))

leppott/InvertExtirp documentation built on Nov. 8, 2019, 5:58 p.m.