View source: R/metric.scores.R
metric.scores | R Documentation |
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)
DF_Metrics |
Data frame of metric values (as columns), Index Name, and Index Region (strata). |
MetricNames |
Names of columns of metric values. |
IndexName |
Nam of column with index (e.g., MBSS.2005.Bugs) |
IndexRegion |
Name of column with relevant bioregion/strata/site class (e.g., COASTAL). |
DF_Thresh |
Data frame of Scoring Thresholds (Index.Name, Index.Region, Metric, Direction, Thresh.Lo, Thresh.Hi, ScoreRegime) |
The function reads the upper limit as greater than or equal (>=). For this reason the Family BIBI thresholds were tweaked and so do not match the published values. The published values use greater than (>) and don't match the mathematical operation used in this function.
The inputs and outputs have been designed to mimic those used by MBSS staff.
The R library dplyr is needed for this function.
vector of scores
# Metrics, Fish
#(generate values then score)s
myIndex <- "MBSS.2005.Fish"
# Thresholds
thresh <- metrics_scoring
# get metric names for myIndex
(myMetrics.Fish <- as.character(unique(thresh[thresh[,
"Index.Name"] == myIndex,"MetricName.Other"])))
# 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)
# 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")
# 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(unique(thresh[thresh[,
"Index.Name"] == myIndex,"MetricName.Other"])))
# 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)
# 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")
# 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)
# Metrics, MSW Index, Benthic Macroinvertebrates, family
myIndex <- "MSW.1999.Bugs"
# Thresholds
thresh <- metrics_scoring
# get metric names for myIndex
(myMetrics.Bugs.MSW <- as.character(unique(thresh[thresh[,
"Index.Name"] == myIndex,"MetricName.Other"])))
# 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)
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.