getBioStressorResponses: Biological Stressor Responses

Description Usage Arguments Details Value Examples

View source: R/getBioStressorResponses.R

Description

Get Biological (Algae or BMI) stressor responses.

Usage

1
2
3
4
getBioStressorResponses(TargetSiteID, stressors, BioResp,
  list.MatchBioData, LogTransf, ref.sites, biocomm = "bmi",
  dir_results = file.path(getwd(), "Results"),
  dir_sub = "StressorResponse", boo_pred_warn = TRUE)

Arguments

TargetSiteID

Site ID

stressors

stressors

BioResp

Biological response variables. For example, BMI metrics or Algae metrics.

list.MatchBioData

list of matched biological (BMI or algae) and stressor data.

LogTransf

Value for if stressor variables should be log10 transformed; 1=TRUE, 0=FALSE.

ref.sites

Reference sites.

biocomm

Biological community; algae or BMI. Default = "BMI".

dir_results

Directory to save plots. Default = working directory and Results.

dir_sub

Subdirectory for outputs from this function. Default = "StressorResponse"

boo_pred_warn

Should warnings for prediction be suppressed. Default = TRUE.

Details

Biological (Algae or BMI) stressor regressions.

Value

A jpg in SiteID subfoler of the "Results" folder of working directory. And two tab-delimited text files; stressor correlations and scores.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
## Not run: 
# Example 1, BMI
TargetSiteID <- "SRCKN001.61"
dir_results <- file.path(getwd(), "Results")
biocomm <- "bmi"

# datasets getSiteInfo
# data, example included with package
data.Stations.Info <- data_Sites       # need for getSiteInfo and getChemDataSubsets
data.SampSummary   <- data_SampSummary
data.303d.ComID    <- data_303d
data.bmi.metrics   <- data_BMIMetrics
data.algae.metrics <- data_AlgMetrics
data.mod           <- data_ReachMod

# Cluster based on elevation category  # need for getSiteInfo and getChemDataSubsets
elev_cat <- toupper(data.Stations.Info[data.Stations.Info[,"StationID_Master"]==TargetSiteID
                    , "ElevCategory"])
if(elev_cat=="HI"){
   data.cluster <- data_Cluster_Hi
} else if(elev_cat=="LO") {
   data.cluster <- data_Cluster_Lo
}

# Map data
# San Diego
#flowline <- rgdal::readOGR(dsn = "data_gis/NHDv2_Flowline_Ecoreg85", layer = "NHDv2_eco85_Project")
#outline <- rgdal::readOGR(dsn = "data_gis/Eco85", layer = "Ecoregion85")
# AZ
map_flowline  <- data_GIS_Flow_HI
map_flowline2 <- data_GIS_Flow_LO
if(elev_cat=="HI"){
   map_flowline <- data_GIS_Flow_HI
} else if(elev_cat=="LO") {
   map_flowline <- data_GIS_Flow_LO
}
map_outline   <- data_GIS_AZ_Outline
# Project site data to USGS Albers Equal Area
usgs.aea <- "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23
              +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83
              +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
# projection for outline
my.aea <- "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 
           +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
map_proj <- my.aea
#
dir_sub <- "SiteInfo"

# Run getSiteInfo
list.SiteSummary <- getSiteInfo(TargetSiteID, dir_results, data.Stations.Info
                                , data.SampSummary, data.303d.ComID
                                , data.bmi.metrics, data.algae.metrics
                                , data.cluster, data.mod
                                , map_proj, map_outline, map_flowline
                                , dir_sub=dir_sub)

# Data getChemDataSubsets
# data import, example 
# data.chem.raw <- read.delim(paste(myDir.Data,"data.chem.raw.tab",sep=""),na.strings = c(""," "))
# data.chem.info <- read.delim(paste(myDir.Data,"data.chem.info.tab",sep=""))
site.COMID <- list.SiteSummary$COMID
site.Clusters <- list.SiteSummary$ClustIDs
# data, example included with package
data.chem.raw <- data_Chem
data.chem.info <- data_ChemInfo

# Run getChemDataSubsets
list.data <- getChemDataSubsets(TargetSiteID, comid=site.COMID, cluster=site.Clusters
                                , data.cluster=data.cluster, data.Stations.Info=data.Stations.Info
                                , data.chem.raw=data.chem.raw, data.chem.info=data.chem.info)

# Data getStressorList
chem.info <- list.data$chem.info
cluster.chem <- list.data$cluster.chem
cluster.samps <- list.data$cluster.samps
ref.sites <- list.data$ref.sites
site.chem <- list.data$site.chem
dir_sub <- "CandidateCauses"

# set cutoff for possible stressor identification
probsLow <- 0.10
probsHigh <- 0.90 

# Run getStressorList
list.stressors <- getStressorList(TargetSiteID, site.Clusters, chem.info, cluster.chem
                                 , cluster.samps, ref.sites, site.chem
                                 , probsHigh, probsLow, biocomm, dir_results
                                 , dir_sub)
                                 
# Data getBioMatches, BMI
## remove "none"
stressors <- list.stressors$stressors[list.stressors$stressors != "none"]
stressors_logtransf <- list.stressors$stressors_LogTransf[list.stressors$stressors != "none"]
LogTransf <- stressors_logtransf
data.bio.metrics <- data_BMIMetrics

# Run getBioMatches
list.MatchBioData <- getBioMatches(stressors, list.data, list.SiteSummary, data.SampSummary
                                   , data.chem.raw, data.bio.metrics, biocomm)
  
# Data getBioStressorResponses, BMI 
BioResp <- c("IBI", "TotalTaxSPL_Sc", "DipTaxSPL_Sc"
             , "IntolTaxSPL_Sc", "HBISPL_Sc", "PlecoPct_Sc", "ScrapPctSPL_Sc"
             , "TrichTax_Sc", "EphemTax_Sc", "EphemPct_Sc", "Dom01PctSPL_Sc") 
dir_sub <- "StressorResponse"
             
# Run getBioStressorResponses, BMI               
getBioStressorResponses(TargetSiteID, stressors, BioResp, list.MatchBioData
                        , LogTransf, ref.sites, biocomm, dir_results, dir_sub)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Example 2, Algae
TargetSiteID <- "LCBEN002.57"
dir_results <- file.path(getwd(), "Results")
biocomm <- "algae"

# datasets getSiteInfo
# data, example included with package
data.Stations.Info <- data_Sites       # need for getSiteInfo and getChemDataSubsets
data.SampSummary   <- data_SampSummary
data.303d.ComID    <- data_303d
data.bmi.metrics   <- data_BMIMetrics
data.algae.metrics <- data_AlgMetrics
data.mod           <- data_ReachMod

#' # Cluster based on elevation category  # need for getSiteInfo and getChemDataSubsets
elev_cat <- toupper(data.Stations.Info[data.Stations.Info[,"StationID_Master"]==TargetSiteID
                    , "ElevCategory"])
if(elev_cat=="HI"){
   data.cluster <- data_Cluster_Hi
} else if(elev_cat=="LO") {
   data.cluster <- data_Cluster_Lo
}

# Map data
# San Diego
#flowline <- rgdal::readOGR(dsn = "data_gis/NHDv2_Flowline_Ecoreg85", layer = "NHDv2_eco85_Project")
#outline <- rgdal::readOGR(dsn = "data_gis/Eco85", layer = "Ecoregion85")
# AZ
map_flowline  <- data_GIS_Flow_HI
map_flowline2 <- data_GIS_Flow_LO
if(elev_cat=="HI"){
   map_flowline <- data_GIS_Flow_HI
} else if(elev_cat=="LO") {
   map_flowline <- data_GIS_Flow_LO
}
map_outline   <- data_GIS_AZ_Outline
# Project site data to USGS Albers Equal Area
usgs.aea <- "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23
              +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83
              +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
# projection for outline
my.aea <- "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 
           +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"
map_proj <- my.aea
#
dir_sub <- "SiteInfo"

# Run getSiteInfo
list.SiteSummary <- getSiteInfo(TargetSiteID, dir_results, data.Stations.Info
                                , data.SampSummary, data.303d.ComID
                                , data.bmi.metrics, data.algae.metrics
                                , data.cluster, data.mod
                                , map_proj, map_outline, map_flowline
                                , dir_sub=dir_sub)

# Data getChemDataSubsets
# data, example included with package
data.chem.raw <- data_Chem
data.chem.info <- data_ChemInfo
site.COMID <- list.SiteSummary$COMID
site.Clusters <- list.SiteSummary$ClustIDs
dir_sub <- "CandidateCauses"

# Run getChemDataSubsets
list.data <- getChemDataSubsets(TargetSiteID, comid=site.COMID, cluster=site.Clusters
                                , data.cluster=data.cluster, data.Stations.Info=data.Stations.Info
                                , data.chem.raw=data.chem.raw, data.chem.info=data.chem.info)

# Data getStressorList
chem.info <- list.data$chem.info
cluster.chem <- list.data$cluster.chem
cluster.samps <- list.data$cluster.samps
ref.sites <- list.data$ref.sites
site.chem <- list.data$site.chem

# set cutoff for possible stressor identification
probsLow <- 0.10
probsHigh <- 0.90 
biocomm <- "algae"

# Run getStressorList
list.stressors <- getStressorList(TargetSiteID, site.Clusters, chem.info, cluster.chem
                                 , cluster.samps, ref.sites, site.chem
                                 , probsHigh, probsLow, biocomm, dir_results)
                                 
# Data getBioMatches, Algae
## remove "none"
stressors <- list.stressors$stressors[list.stressors$stressors != "none"]
stressors_logtransf <- list.stressors$stressors_LogTransf[list.stressors$stressors != "none"]
LogTransf <- stressors_logtransf
data.bio.metrics <- data_AlgMetrics

# Run getBioMatches, Algae
list.MatchBioData <- getBioMatches(stressors, list.data, list.SiteSummary, data.SampSummary
                                  , data.chem.raw, data.bio.metrics, biocomm)

# Data getBioStressorResponses, Algae
BioResp <- colnames(data.bio.metrics[6:52])
dir_sub <- "StressorResponse"

# Run getBioStressorResponses, Algae
getBioStressorResponses(TargetSiteID, stressors, BioResp, list.MatchBioData
                       , LogTransf, ref.sites, biocomm, dir_results, dir_sub)

## End(Not run)

leppott/CASTfxn documentation built on Sept. 6, 2019, 11:04 p.m.