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.

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.

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).

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

Examples

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())
#> [1] 1 1 1
#> [1] 2 1 1
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 3 1 1
#> [1] 4 1 1
#> [1] 5 1 1
#> [1] 6 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 7 1 1
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 8 1 1
#> [1] 9 1 1
#> [1] 10 1 1
#> [1] 11 1 1
#> [1] 12 1 1
#> [1] 13 1 1
#> [1] 14 1 1
#> [1] 15 1 1
#> [1] 16 1 1
#> [1] 17 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 18 1 1
#> [1] 19 1 1
#> [1] 20 1 1
#> [1] 21 1 1
#> [1] 22 1 1
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: algorithm did not converge
#> [1] 23 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 24 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 25 1 1
#> [1] 26 1 1
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 27 1 1
#> [1] 28 1 1
#> [1] 29 1 1
#> [1] 30 1 1
#> [1] 31 1 1
#> [1] 32 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 33 1 1
#> [1] 34 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 35 1 1
#> [1] 36 1 1
#> [1] 37 1 1
#> [1] 38 1 1
#> [1] 39 1 1
#> [1] 40 1 1
#> [1] 41 1 1
#> [1] 42 1 1
#> [1] 43 1 1
#> [1] 44 1 1
#> [1] 45 1 1
#> [1] 46 1 1
#> [1] 47 1 1
#> [1] 48 1 1
#> [1] 49 1 1
#> [1] 50 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 51 1 1
#> [1] 52 1 1
#> [1] 53 1 1
#> [1] 54 1 1
#> [1] 55 1 1
#> [1] 56 1 1
#> [1] 57 1 1
#> [1] 58 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 59 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 60 1 1
#> [1] 61 1 1
#> [1] 62 1 1
#> [1] 63 1 1
#> [1] 64 1 1
#> [1] 65 1 1
#> [1] 66 1 1
#> [1] 67 1 1
#> [1] 68 1 1
#> [1] 69 1 1
#> [1] 70 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 71 1 1
#> [1] 72 1 1
#> [1] 73 1 1
#> [1] 74 1 1
#> [1] 75 1 1
#> [1] 76 1 1
#> [1] 77 1 1
#> [1] 78 1 1
#> [1] 79 1 1
#> [1] 80 1 1
#> [1] 81 1 1
#> [1] 82 1 1
#> [1] 83 1 1
#> [1] 84 1 1
#> [1] 85 1 1
#> [1] 86 1 1
#> [1] 87 1 1
#> [1] 88 1 1
#> [1] 89 1 1
#> [1] 90 1 1
#> [1] 91 1 1
#> [1] 92 1 1
#> [1] 93 1 1
#> [1] 94 1 1
#> [1] 95 1 1
#> [1] 96 1 1
#> [1] 97 1 1
#> [1] 98 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 99 1 1
#> [1] 100 1 1
#> [1] 101 1 1
#> [1] 102 1 1
#> [1] 103 1 1
#> [1] 104 1 1
#> [1] 105 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 106 1 1
#> [1] 107 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 108 1 1
#> [1] 109 1 1
#> [1] 110 1 1
#> [1] 111 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 112 1 1
#> [1] 113 1 1
#> [1] 114 1 1
#> [1] 115 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 116 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 117 1 1
#> [1] 118 1 1
#> [1] 119 1 1
#> [1] 120 1 1
#> [1] 121 1 1
#> [1] 122 1 1
#> [1] 123 1 1
#> [1] 124 1 1
#> [1] 125 1 1
#> [1] 126 1 1
#> [1] 127 1 1
#> [1] 128 1 1
#> [1] 129 1 1
#> [1] 130 1 1
#> [1] 131 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 132 1 1
#> [1] 133 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 134 1 1
#> [1] 135 1 1
#> [1] 136 1 1
#> [1] 137 1 1
#> [1] 138 1 1
#> [1] 139 1 1
#> [1] 140 1 1
#> [1] 141 1 1
#> [1] 142 1 1
#> [1] 143 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 144 1 1
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: algorithm did not converge
#> [1] 145 1 1
#> [1] 146 1 1
#> [1] 147 1 1
#> [1] 148 1 1
#> [1] 149 1 1
#> [1] 150 1 1
#> [1] 151 1 1
#> [1] 152 1 1
#> [1] 153 1 1
#> [1] 154 1 1
#> [1] 155 1 1
#> [1] 156 1 1
#> [1] 157 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 158 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 159 1 1
#> [1] 160 1 1
#> [1] 161 1 1
#> [1] 162 1 1
#> [1] 163 1 1
#> [1] 164 1 1
#> [1] 165 1 1
#> [1] 166 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> [1] 167 1 1
#> [1] 168 1 1
#> [1] 169 1 1
#> [1] 170 1 1
#> [1] 171 1 1
#> [1] 172 1 1
#> [1] 173 1 1
#> [1] 174 1 1
#> [1] 175 1 1
#> [1] 176 1 1
#> [1] 177 1 1
#> [1] 178 1 1
#> [1] 179 1 1
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# view returned data frame View(cond.opt) # open saved PDF system(paste0('open "',file.path(getwd(),region,"results.taxon.gam.pdf"),'"'))
#> [1] 0