If you use hydroGOF, please cite it as Zambrano-Bigiarini (2026):
Zambrano-Bigiarini, M. (2026) hydroGOF: Goodness-of-fit functions for comparison of simulated and observed hydrological time series R package version 0.7-0. URL: https://cran.r-project.org/package=hydroGOF. doi:10.32614/CRAN.package.hydroGOF.
Installing the latest stable version (from CRAN):
Alternatively, you can also try the under-development version (from Github):
Loading the hydroGOF package, which contains data and functions used in this analysis:
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
The following examples use the well-known Nash-Sutcliffe efficiency (NSE), but you can repeat the computations using any of the goodness-of-fit measures included in the hydroGOF package (e.g., KGE, ubRMSE, dr).
Basic ideal case with a numeric sequence of integers:
## [1] 1
## [1] 0.8787879
Basic ideal case with a numeric sequence of integers:
## [1] 1
## [1] 0.8787879
From this example onwards, a streamflow time series will be used.
First, we load the daily streamflows of the Ega River (Spain), from 1961 to 1970:
Generating a simulated daily time series, initially equal to the observed series:
Visualising the observed and simulated time series:
Computing the ‘NSE’ for the “best” (unattainable) case
## [1] 1
NSE for simulated values equal to observations plus random noise on the first half of the observed values.
This random noise has more relative importance for low flows than for medium and high flows.
Randomly changing the first 1826 elements of ‘sim’, by using a normal distribution with mean 10 and standard deviation equal to 1 (default of ‘rnorm’).
## [1] 0.8739233
Let’s have a look at other goodness-of-fit measures:
## [1] 0.6049353
## [1] -0.5462133
## [1] 0.9769437
## [1] 0.9685997
## [1] 0.6805676
## [1] 0.6168535
## [1] 0.7461033
## [1] 0.517451
## [1] 0.6337526
## [1] 0.6544168
## [1] 0.6467695
## [1] 0.6084504
## [1] 0.9697094
## [1] 0.8024676
## [1] 0.7979285
## [1] 0.6285137
## [1] 0.6838346
## [1] 0.468186
## [1] 0.03075188
## [1] 0.08249524
## [1] 0.6838218
## [1] 0.6777607
## [1] 0.3164055
## [1] 31.6
## [Note: 'thr.shw' was set to FALSE to avoid confusing legends...]
## [1] -35.37753
## [1] 4.999291
## [1] 4.999291
## [1] 50.49381
## [1] 7.1059
## [1] 5.049841
## [1] 35.5
## [1] 3
## [1] 44.9
## [1] 47.1
## [1] 0.969776
## [1] 0.8357504
## [1] 0.8739233
## [1] 0.778017
NSE for simulated values equal to observations plus random noise on the first half of the observed values and applying (natural) logarithm to obs against sim during computations.
## [1] 0.4800871
Verifying the previous value:
## [1] 0.4800871
Let’s have a look at other goodness-of-fit measures:
## [1] 0.6049353
## [1] -0.5462133
## [1] 0.9769437
## [1] 0.9685997
## [1] 0.6805676
## [1] 0.6168535
## [1] 0.7461033
## [1] 0.517451
## [1] 0.6337526
## [1] 0.6544168
## [1] 0.6467695
## [1] 0.6084504
## [1] 0.9697094
## [1] 0.8024676
## [1] 0.7979285
## [1] 0.6285137
## [1] 0.6838346
## [1] 0.468186
## [1] 0.03075188
## [1] 0.08249524
## [1] 0.6838218
## [1] 0.6777607
## [1] 0.3164055
## [1] 31.6
## [Note: 'thr.shw' was set to FALSE to avoid confusing legends...]
## [1] -35.37753
## [1] 4.999291
## [1] 4.999291
## [1] 50.49381
## [1] 7.1059
## [1] 5.049841
## [1] 35.5
## [1] 3
## [1] 44.9
## [1] 47.1
## [1] 0.969776
## [1] 0.8357504
## [1] 0.8739233
## [1] 0.778017
NSE for simulated values equal to observations plus random noise on the first half of the observed values and applying (natural) logarithm to obs against sim and adding the Pushpalatha2012 constant during computations.
## [1] 0.4872317
Verifying the previous value, with the epsilon value following Pushpalatha2012:
## [1] 0.4872317
Let’s have a look at other goodness-of-fit measures:
gof(sim=sim, obs=obs, fun=log, epsilon.type="Pushpalatha2012", do.spearman=TRUE, do.pbfdc=TRUE, do.pmr=TRUE)## [,1]
## ME 0.41
## MAE 0.41
## MSE 0.46
## RMSE 0.68
## ubRMSE 0.54
## NRMSE % 71.60
## PBIAS % 18.20
## RSR 0.72
## rSD 0.89
## NSE 0.49
## mNSE 0.48
## rNSE -2.00
## wNSE 0.74
## wsNSE 0.78
## d 0.86
## dr 0.74
## md 0.74
## rd 0.20
## cp -7.68
## r 0.83
## R2 0.49
## bR2 0.44
## VE 0.82
## KGE 0.72
## KGElf 0.52
## KGEnp 0.74
## KGEkm 0.74
## JDKGE 0.72
## LME 0.68
## LCE 0.67
## sKGE 0.53
## APFB 0.01
## HFB 0.02
## rSpearman 0.84
## pbiasFDC % -46.31
## PMR 0.20
NSE for simulated values equal to observations plus random noise on the first half of the observed values and applying (natural) logarithm to obs against sim and adding a user-defined constant during computations
## [1] 0.4805544
Verifying the previous value:
## [1] 0.4805544
Let’s have a look at other goodness-of-fit measures:
gof(sim=sim, obs=obs, fun=log, epsilon.type="otherValue", epsilon.value=eps, do.spearman=TRUE, do.pbfdc=TRUE, do.pmr=TRUE)## [,1]
## ME 0.42
## MAE 0.42
## MSE 0.48
## RMSE 0.69
## ubRMSE 0.55
## NRMSE % 72.10
## PBIAS % 18.70
## RSR 0.72
## rSD 0.88
## NSE 0.48
## mNSE 0.48
## rNSE -3.98
## wNSE 0.74
## wsNSE 0.78
## d 0.86
## dr 0.74
## md 0.74
## rd -0.33
## cp -7.93
## r 0.82
## R2 0.48
## bR2 0.43
## VE 0.81
## KGE 0.72
## KGElf 0.51
## KGEnp 0.74
## KGEkm 0.73
## JDKGE 0.71
## LME 0.67
## LCE 0.66
## sKGE 0.48
## APFB 0.01
## HFB 0.02
## rSpearman 0.84
## pbiasFDC % -46.79
## PMR 0.21
NSE for simulated values equal to observations plus random noise on the first half of the observed values and applying (natural) logarithm to obs against sim and using a user-defined factor to multiply the mean of the observed values to obtain the constant to be added to obs against sim during computations
## [1] 0.4939063
Verifying the previous value:
fact <- 1/50
eps <- fact*mean(obs, na.rm=TRUE)
lsim <- log(sim+eps)
lobs <- log(obs+eps)
NSE(sim=lsim, obs=lobs)## [1] 0.4939063
Let’s have a look at other goodness-of-fit measures:
gof(sim=sim, obs=obs, fun=log, epsilon.type="otherFactor", epsilon.value=fact, do.spearman=TRUE, do.pbfdc=TRUE, do.pmr=TRUE)## [,1]
## ME 0.41
## MAE 0.41
## MSE 0.44
## RMSE 0.66
## ubRMSE 0.52
## NRMSE % 71.10
## PBIAS % 17.60
## RSR 0.71
## rSD 0.89
## NSE 0.49
## mNSE 0.48
## rNSE -1.29
## wNSE 0.74
## wsNSE 0.78
## d 0.87
## dr 0.74
## md 0.74
## rd 0.39
## cp -7.43
## r 0.83
## R2 0.49
## bR2 0.44
## VE 0.82
## KGE 0.73
## KGElf 0.53
## KGEnp 0.74
## KGEkm 0.75
## JDKGE 0.72
## LME 0.68
## LCE 0.68
## sKGE 0.56
## APFB 0.01
## HFB 0.02
## rSpearman 0.84
## pbiasFDC % -45.81
## PMR 0.19
NSE for simulated values equal to observations plus random noise on the first half of the observed values and applying a user-defined function to obs against sim during computations:
## [1] 0.7263728
Verifying the previous value, with the epsilon value following Pushpalatha2012:
## [1] 0.7263728
## [,1]
## ME 0.65
## MAE 0.65
## MSE 0.92
## RMSE 0.96
## ubRMSE 0.71
## NRMSE % 52.30
## PBIAS % 17.70
## RSR 0.52
## rSD 0.97
## NSE 0.73
## mNSE 0.54
## rNSE 0.34
## wNSE 0.89
## wsNSE 0.76
## d 0.93
## dr 0.77
## md 0.76
## rd 0.83
## cp -1.17
## r 0.92
## R2 0.73
## bR2 0.65
## VE 0.82
## KGE 0.81
## KGElf 0.51
## KGEnp 0.75
## KGEkm 0.80
## JDKGE 0.79
## LME 0.80
## LCE 0.79
## sKGE 0.84
## APFB 0.02
## HFB 0.04
## rSpearman 0.84
## pbiasFDC % -33.38
## PMR 0.19
Loading observed streamflows of the Ega River (Spain), with daily data from 1961-Jan-01 up to 1970-Dec-31
Generating a simulated daily time series, initially equal to the observed values (simulated values are usually read from the output files of the hydrological model)
Plotting the graphical comparison of obs against sim, along with the default goodness-of-fit measures:
Plotting the graphical comparison of obs against sim, along with user-defined goodness-of-fit measures:
Computing the numeric goodness-of-fit measures for the best (unattainable) case, including the following three measures that -due to slightly high computation time- are not computed by default: i) the Spearman’s Rank Correlation Coefficient (rSpearman), ii) the percent bias in the Slope of the Midsegment of the Flow Duration Curve (pbiasFDC), and iii) the Proxy for Model Robustness (PMR).
## [,1]
## ME 0
## MAE 0
## MSE 0
## RMSE 0
## ubRMSE 0
## NRMSE % 0
## PBIAS % 0
## RSR 0
## rSD 1
## NSE 1
## mNSE 1
## rNSE 1
## wNSE 1
## wsNSE 1
## d 1
## dr 1
## md 1
## rd 1
## cp 1
## r 1
## R2 1
## bR2 1
## VE 1
## KGE 1
## KGElf 1
## KGEnp 1
## KGEkm 1
## JDKGE 1
## LME 1
## LCE 1
## sKGE 1
## APFB 0
## HFB 0
## rSpearman 1
## pbiasFDC % 0
## PMR 0
Plotting the graphical comparison of obs against sim, along with the default goodness-of-fit measures for the daily and monthly time series:
Plotting the graphical comparison of obs against sim, along with user-defined goodness-of-fit measures for the daily and monthly time series:
ggof(sim=sim, obs=obs, ftype="dm", FUN=mean,
gofs=c( "PBIAS", "dr", "R2", "NSE", "KGE", "LCE", "JDKGE", "APFB", "HFB"))Using the first two years (1961-1962) as warm-up period, and removing the corresponding observed and simulated values from the computation of the goodness-of-fit measures:
Verification of the goodness-of-fit measures for the daily values after removing the warm-up period:
## [,1]
## ME 3.74
## MAE 3.74
## MSE 37.77
## RMSE 6.15
## ubRMSE 4.87
## NRMSE % 33.70
## PBIAS % 25.20
## RSR 0.34
## rSD 1.02
## NSE 0.89
## mNSE 0.68
## rNSE -0.48
## wNSE 0.98
## wsNSE 0.82
## d 0.97
## dr 0.84
## md 0.84
## rd 0.64
## cp 0.52
## r 0.97
## R2 0.89
## bR2 0.81
## VE 0.75
## KGE 0.74
## KGElf 0.57
## KGEnp 0.69
## KGEkm 0.73
## JDKGE 0.74
## LME 0.75
## LCE 0.74
## sKGE 0.70
## APFB 0.02
## HFB 0.00
Generating fictitious lower and upper uncertainty bounds:
Plotting the previously generated uncertainty bands:
Randomly generating a simulated time series:
Plotting the previously generated simulated time series along the observations and the uncertainty bounds:
The P-factor quantifies the percentage of observed values that fall within the prediction uncertainty band defined by the lower and upper bounds. It is a measure of the coverage of the uncertainty interval.
The P-factor ranges from 0 to 1. A value of 1 indicates that all observations are bracketed by the uncertainty bounds, whereas a value of 0 indicates that none of the observations fall within the bounds.
Computing the P-factor:
## [1] 0.9993155
The R-factor quantifies the average width of the prediction uncertainty band relative to the variability of the observed data. It is a measure of the magnitude of predictive uncertainty associated with a model simulation.
The R-factor ranges from 0 to infinity, with an optimal value of 0 indicating perfect agreement between simulated and observed values (i.e., zero prediction uncertainty). In practical applications, the R-factor represents the width of the uncertainty interval and should be as small as possible. Values close to or smaller than 1 are commonly considered indicative of an acceptable level of predictive uncertainty, although acceptable thresholds depend on the quality of observations and the modelling context.
Computing the R-factor:
## [1] 0.5488274
Important note:
Because a larger fraction of observations can often be bracketed by widening the uncertainty bounds, the R-factor is typically interpreted jointly with the P-factor. A balance between a high P-factor (good coverage) and a low R-factor (narrow uncertainty bounds) is therefore sought during model calibration and uncertainty analysis.
Computing the daily residuals (even if this is a dummy example, it is enough for illustrating the capability)
Summarizing and plotting the residuals (it requires the hydroTSM package):
## Index r
## Min. 1963-01-01 -1.6160
## 1st Qu. 1964-12-31 2.3300
## Median 1966-12-31 3.0360
## Mean 1966-12-31 3.0330
## 3rd Qu. 1968-12-30 3.7470
## Max. 1970-12-31 7.3350
## IQR <NA> 1.4163
## sd <NA> 1.0413
## cv <NA> 0.3433
## Skewness <NA> -0.0089
## Kurtosis <NA> 0.1889
## NA's <NA> 2.0000
## n <NA> 2922.0000
Seasonal plots and boxplots
This tutorial was built under:
## [1] "x86_64-pc-linux-gnu"
## [1] "R version 4.6.0 (2026-04-24)"
## [1] "hydroGOF 0.7-0"