Learn R Programming

Mass Balance Regression

This package implements the Mass-balance-adjusted regression algorithm for sub-annual streamflow reconstruction. The algorithm implements a penalty term to minimize the differences between the total seasonal flow reconstruction and the annual flow reconstruction. Details are presented in Nguyen et al (2020).

Currently the package is only available on GitHub, but it will be available on CRAN soon.

To install the development from GitHub

install.packages('remotes')
remotes::install_github('ntthung/mbr')

The package has two main functions, mb_reconstruction() for reconstruction, and cv_mb() for cross-validation.

Example reconstruction

fit <- mb_reconstruction(
  instQ = p1Seasonal,
  pc.list = pc3seasons,
  start.year = 1750,
  lambda = 1,
  log.trans = 1:3
)

Example cross-validation

# Create hold-out chunks
set.seed(24)
cvFolds <- make_Z(
  obs = 1922:2003,
  nRuns = 50, 
  frac = 0.25,
  contiguous = TRUE
)
# Run cross validation
cv <- cv_mb(
  instQ = p1Seasonal,
  pc.list = pc3seasons,
  cv.folds = cvFolds,
  start.year = 1750,
  lambda = 1,
  log.trans = 1:3,
  return.type = 'metric means'
)
# Round up to two decimal places
cv[, (2:6) := lapply(.SD, round, digits = 2), .SDcols = 2:6][]

Type browseVignettes('mbr') for details.

References

Nguyen, H. T. T., Galelli, S., Xu, C., & Buckley, B. (2020). Multi-Proxy, Multi-Season Streamflow Reconstruction with Mass Balance Adjustment. Earth and Space Science Open Archive, 22. https://doi.org/10.1002/essoar.10504791.1

Copy Link

Version

Install

install.packages('mbr')

Monthly Downloads

260

Version

0.0.1

License

GPL (>= 2.0)

Issues

Pull Requests

Stars

Forks

Maintainer

Hung Nguyen

Last Published

February 16th, 2021

Functions in mbr (0.0.1)

rowScale

Scale rows of a Matrix
p1Seasonal

Seasonal streamflow at P.1 station
obj_fun

Objective function from parameters
rowUnscale

Unscale rows of a matrix
mb_reconstruction

Mass-balance-adjusted reconstruction
mb_fit

Fit parameters with mass balance criterion
cv_mb

Cross-validation
nRMSE

Normalized root-mean-square error
mbr

mbr: Mass Balance Reconstruction
pc3seasons

Principal components of tree rings
prepend_ones

Prepend a column of ones
lsq_mb

Least square with mass balance penalty
RE

Reduction of Error
KGE

Kling-Gupta Efficiency
calculate_metrics

Reconstruction metrics
make_Z

Make cross-validation folds.
colScale

Scale columns of a matrix
colUnscale

Unscale columns of a matrix
NSE

Nash-Sutcliffe Efficiency
back_trans

Back-transformation