This function calculates metric scores based on a Thresholds data frame. Can generate scores for 1/3/5 (ScoreRegime="135") for MD DNR MBSS FIBI and BIBI.
metric.scores(DF_Metrics, MetricNames, IndexName, IndexRegion, DF_Thresh)
Data frame of metric values (as columns), Index Name, and Index Region (strata).
Names of columns of metric values.
Nam of column with index (e.g., MBSS.2005.Bugs)
Name of column with relevant bioregion/strata/site class (e.g., COASTAL).
Data frame of Scoring Thresholds (Index.Name, Index.Region, Metric, Direction, Thresh.Lo, Thresh.Hi, ScoreRegime)
vector of scores
The inputs and outputs have been designed to mimic those used by MBSS staff.
The R library dplyr is needed for this function.
# Metrics, Fish
#(generate values then score)s
myIndex <- "MBSS.2005.Fish"
# Thresholds
thresh <- metrics_scoring
# get metric names for myIndex
(myMetrics.Fish <- as.character(droplevels(unique(thresh[thresh[,
"Index.Name"]==myIndex,"MetricName.Other"]))))
#> [1] "ABUNSQM" "NUMBENTSP" "PTOL" "PGEOMIV" "PROUND" "PABDOM"
#> [7] "BIOM_MSQ" "P_LITH" "P_IS" "PBROOK" "PSCULP"
# Taxa Data
myDF.Fish <- taxa_fish
myMetric.Values.Fish <- metric.values(myDF.Fish, "fish", myMetrics.Fish,
TRUE)
# View(myMetric.Values.Fish)
# SCORE
Metrics.Fish.Scores <- metric.scores(myMetric.Values.Fish, myMetrics.Fish,
"Index.Name", "FIBISTRATA", thresh)
#> One or more fish samples (n = 1) had zero organisms and was scored as a 1
#> (metrics and IBI).
# View Results
# View(Metrics.Fish.Scores)
# Add Narrative
myBreaks <- c(1:5)
myLabels <- c("Very Poor", "Poor", "Fair", "Good")
Metrics.Fish.Scores$IBI_Nar <- cut(Metrics.Fish.Scores$IBI
, breaks=myBreaks
, labels=myLabels
, include.lowest=TRUE
, right=FALSE
, ordered_result=TRUE)
# QC, IBI Numeric vs. Narrative
table(Metrics.Fish.Scores$IBI, Metrics.Fish.Scores$IBI_Nar, useNA="ifany")
#>
#> Very Poor Poor Fair Good
#> 1 4 0 0 0
#> 1.33333333333333 2 0 0 0
#> 1.5 1 0 0 0
#> 1.66666666666667 2 0 0 0
#> 2 0 11 0 0
#> 2.33333333333333 0 6 0 0
#> 2.66666666666667 0 5 0 0
#> 3 0 0 7 0
#> 3.33333333333333 0 0 12 0
#> 3.5 0 0 4 0
#> 3.66666666666667 0 0 22 0
#> 4 0 0 0 33
#> 4.33333333333333 0 0 0 26
#> 4.5 0 0 0 1
#> 4.66666666666667 0 0 0 15
#> 5 0 0 0 9
# Metrics, Index, Benthic Macroinvertebrates, genus
# (generate values then scores)
myIndex <- "MBSS.2005.Bugs"
# Thresholds
thresh <- metrics_scoring
# get metric names for myIndex
(myMetrics.Bugs.MBSS <- as.character(droplevels(unique(thresh[thresh[,
"Index.Name"]==myIndex,"MetricName.Other"]))))
#> [1] "ntaxa" "nept" "nephem" "pintol_urb" "pephem"
#> [6] "nscrape" "pclimb" "pchiron" "pcling" "ptany"
#> [11] "pscrape" "pswim" "pdipt"
# Taxa Data
myDF.Bugs.MBSS <- taxa_bugs_genus
myMetric.Values.Bugs.MBSS <- metric.values(myDF.Bugs.MBSS, "bugs",
myMetrics.Bugs.MBSS)
# View(myMetric.Values.Bugs.MBSS)
# SCORE
Metrics.Bugs.Scores.MBSS <- metric.scores(myMetric.Values.Bugs.MBSS,
myMetrics.Bugs.MBSS, "INDEX.NAME", "STRATA_R", thresh)
#> One or more bug samples had < 60 (n = 0) or > 120 (n = 90) organisms.
#>
#> These samples should be further examined.
# View Results
# View(Metrics.Bugs.Scores.MBSS)
# Add Narrative
myBreaks <- c(1:5)
myLabels <- c("Very Poor", "Poor", "Fair", "Good")
Metrics.Bugs.Scores.MBSS$IBI_Nar <- cut(Metrics.Bugs.Scores.MBSS$IBI
, breaks=myBreaks
, labels=myLabels
, include.lowest=TRUE
, right=FALSE
, ordered_result=TRUE)
# QC, IBI Numeric vs. Narrative
table(Metrics.Bugs.Scores.MBSS$IBI
, Metrics.Bugs.Scores.MBSS$IBI_Nar
, useNA="ifany")
#>
#> Very Poor Poor Fair Good
#> 1 3 0 0 0
#> 1.28571428571429 2 0 0 0
#> 1.33333333333333 7 0 0 0
#> 1.5 5 0 0 0
#> 1.57142857142857 3 0 0 0
#> 1.66666666666667 10 0 0 0
#> 1.75 7 0 0 0
#> 1.85714285714286 3 0 0 0
#> 2 0 13 0 0
#> 2.14285714285714 0 5 0 0
#> 2.25 0 7 0 0
#> 2.33333333333333 0 6 0 0
#> 2.42857142857143 0 9 0 0
#> 2.5 0 3 0 0
#> 2.66666666666667 0 14 0 0
#> 2.71428571428571 0 6 0 0
#> 3 0 0 18 0
#> 3.25 0 0 3 0
#> 3.28571428571429 0 0 4 0
#> 3.33333333333333 0 0 8 0
#> 3.5 0 0 4 0
#> 3.57142857142857 0 0 2 0
#> 3.66666666666667 0 0 11 0
#> 3.75 0 0 4 0
#> 3.85714285714286 0 0 2 0
#> 4 0 0 0 9
#> 4.14285714285714 0 0 0 6
#> 4.25 0 0 0 7
#> 4.33333333333333 0 0 0 2
#> 4.42857142857143 0 0 0 5
#> 4.5 0 0 0 3
#> 4.66666666666667 0 0 0 2
#> 4.71428571428571 0 0 0 7
#> 4.75 0 0 0 3
#> 5 0 0 0 8
# QC bug count
Metrics.Bugs.Scores.MBSS[Metrics.Bugs.Scores.MBSS[,"totind"]>120,
"QC_Count"] <- "LARGE"
Metrics.Bugs.Scores.MBSS[Metrics.Bugs.Scores.MBSS[,"totind"]<60,
"QC_Count"] <- "SMALL"
Metrics.Bugs.Scores.MBSS[is.na(Metrics.Bugs.Scores.MBSS[,"QC_Count"]),
"QC_Count"] <- "OK"
# table of QC_Count
table(Metrics.Bugs.Scores.MBSS$QC_Count)
#>
#> LARGE OK
#> 90 121
# Metrics, MSW Index, Benthic Macroinvertebrates, family
myIndex <- "MSW.1999.Bugs"
# Thresholds
thresh <- metrics_scoring
# get metric names for myIndex
(myMetrics.Bugs.MSW <- as.character(droplevels(unique(thresh[thresh[,
"Index.Name"]==myIndex,"MetricName.Other"]))))
#> [1] "ntaxa" "nept" "nephem" "ndipt" "pephem"
#> [6] "nintol_FAM" "becks"
# Taxa Data
myDF.Bugs.MSW <- taxa_bugs_family
myMetric.Values.Bugs.MSW <- metric.values(myDF.Bugs.MSW, "bugs",
myMetrics.Bugs.MSW)
# View(myMetric.Values.Bugs.MSW)
# SCORE
Metrics.Bugs.Scores.MSW <- metric.scores(myMetric.Values.Bugs.MSW,
myMetrics.Bugs.MSW, "INDEX.NAME", "STRATA_R", thresh)
#> One or more bug samples had < 60 (n = 0) or > 120 (n = 102) organisms.
#>
#> These samples should be further examined.
# View Results
# View(Metrics.Bugs.Scores.MSW)
# Add Narrative
myBreaks <- c(1:5)
myLabels <- c("Very Poor", "Poor", "Fair", "Good")
Metrics.Bugs.Scores.MSW$IBI_Nar <- cut(Metrics.Bugs.Scores.MSW$IBI
, breaks=myBreaks
, labels=myLabels
, include.lowest=TRUE
, right=FALSE
, ordered_result=TRUE)
# QC, IBI Numeric vs. Narrative
table(Metrics.Bugs.Scores.MSW$IBI, Metrics.Bugs.Scores.MSW$IBI_Nar
, useNA="ifany")
#>
#> Very Poor Poor Fair Good
#> 1 4 0 0 0
#> 1.28571428571429 14 0 0 0
#> 1.57142857142857 18 0 0 0
#> 1.85714285714286 20 0 0 0
#> 2.14285714285714 0 17 0 0
#> 2.42857142857143 0 22 0 0
#> 2.71428571428571 0 16 0 0
#> 3 0 0 21 0
#> 3.28571428571429 0 0 14 0
#> 3.57142857142857 0 0 15 0
#> 3.85714285714286 0 0 15 0
#> 4.14285714285714 0 0 0 11
#> 4.42857142857143 0 0 0 24