R/H20.r

Defines functions calcH20 H20

Documented in H20

#' Compute H20 IBI
#' 
#' Computes H20 IBI score and QC.
#' 
#' @param data User data merged with metadata, as generated by \code{\link{taxonInfo}}
#' @param all If false (default), return only SampleID, H20 IBI and QC. Else, all metrics are returned.
#
#' @export
#' @examples
#' data(algaeSamples)
#' preparedData <- taxonInfo(validator(algaeSamples))
#' H20(preparedData$cleanData)
#' 
#' 

H20 <- function(data, all=FALSE){
  
  metrics <- alg.metrics(data)
  calcH20(metrics, all)
  
}

calcH20 <- function(metrics, all=FALSE){
  metrics$H20 <- 10 * rowMeans(metrics[,c("SCALED.sed.tol.high", "SCALED.low.N",
                                          "SCALED.N.het","SCALED.DO.50",
                                          "SCALED.halo","SCALED.high.Cu.sp",
                                          "SCALED.high.DOC.sp","SCALED.low.TP.sp")])
  metrics$H20.QCmin <- apply(metrics[,c("QC.sed.tol.PropValvesWithTraits",
                                        "QC.Ptrait.PropValvesWithTraits",
                                        "QC.N.het.PropValvesWithTraits",
                                        "QC.DO.PropValvesWithTraits",
                                        "QC.halo.PropValvesWithTraits",
                                        "propBiovolChlor.QC.propBiovolWithTraits",
                                        "propBiovolChlor.QC.propBiovolWithTraits",
                                        "high.Cu.sp.QC.propBiovolWithTraits",
                                        "high.Cu.sp.QC.propTaxaWithTraits",
                                        "high.DOC.sp.QC.propBiovolWithTraits",
                                        "high.DOC.sp.QC.propTaxaWithTraits",
                                        "low.TP.sp.QC.propBiovolWithTraits",
                                        "low.TP.sp.QC.propTaxaWithTraits")],
                             1, min)
  
  if(all){
    metrics
  } else {
    metrics[, c("SampleID", "H20", "H20.QCmin")]
  }
}
SCCWRP/algaeMetrics documentation built on Oct. 27, 2021, 2:29 a.m.