makePeakMatrix: Make Peak Lower- and Upper-Bounds Matrix from Peak Discharge...

makePeakMatrixR Documentation

Make Peak Lower- and Upper-Bounds Matrix from Peak Discharge Qualification Codes

Description

Make peak lower- and upper-bounds matrix from peak discharge qualification codes for left- and right-bounds (limits) based on the less than and greater than censoring.

Usage

makePeakMatrix(x, lo=0, hi=NA, eps=sqrt(.Machine$double.eps), wypad=FALSE)

Arguments

x

A data.frame having been run through splitPeakCodes first, but if columns resulting from those two functions are are not detected, then the water year column and code split are made internally and subset to appearsSystematic but not returned;

lo

The lower (left) bounds for isCode4 peaks, but if it is NA, then the minimum of the real peak streamflows minus the eps is used with protection against going below zero;

hi

The upper (right) bounds for isCode8 peaks, but if it is NA, then the maximum of the real peak streamflows plus the eps is used;

eps

A small number subtracted from the lower (left) or added to the upper (right) bounds when computed internally when lo and hi, respectively, are NA; and

wypad

A logical to left append two columns of NA to the lower (right) and upper (right) bounds. This feature is provided to support an input structure used within the copBasic package.

Value

A two- or four-column matrix is returned depending on argument wypad with row names set as the water year.

Author(s)

W.H. Asquith

See Also

splitPeakCodes

Examples

## Not run: 
  # Example of a streamflow site with several less and greater than annual peaks.
  site <- "08136220"; # another good test is "02370750"
  r <- 1E3; par(ljoin=1); myblu <- rgb(0, 0.3, 0.7, 0.2)
  pk   <- splitPeakCodes(dataRetrieval::readNWISpeak(site, convert=FALSE))
  pk   <- pk[pk$appearsSystematic,]
  plotPeaks(pk, xlab="Water Year", ylab="Streamflow, cfs")
  mtext(site, line=0, font=2)
  zmat <- makePeakMatrix(pk, wypad=TRUE); Y <- pk$water_yr; Q <- pk$peak_va
  S1 <- copBasic::wolfCOPtest(Y,Q, zmat=zmat, rndphi=r)
  d1 <- S1$table # plot sigmas and p-values based on z-matrix (using codes 4 and 8)
  S2 <- copBasic::wolfCOPtest(Y,Q, zmat=NULL, rndphi=r, ties.method="average")
  d2 <- S2$table # plot sigmas and p-values of a potentially naive ties averaging.
  S3 <- copBasic::wolfCOPtest(Y,Q, zmat=NULL, rndphi=r, ties.method="random" )
  d3 <- S3$table # plot sigmas and p-values by randomization of the ties
  plot(  d1$sigmas, d1$sigmas_pvl, pch=16, col=myblu, xlab="Sigma", ylab="p-value",
         xlim=c(0,1), ylim=c(0,1))
  points(d2$sigmas, d2$sigmas_pvl, pch=25, col="green4", cex=2.1, bg="white", lwd=2)
  points(d3$sigmas, d3$sigmas_pvl, pch=24, col="red",    cex=1.4, bg="white", lwd=2)
  lines( d1$sigmas, d1$sigmas_pvl, col="blue")
  mtext(site, line=1, font=2) #
## End(Not run)

MGBT documentation built on Oct. 5, 2026, 9:07 a.m.