Gof

Compute a composite set of goodness-of-fit metrics between observed and simulated values. Missing values are filtered pairwise, and optional rounding is supported via n_small. By default, gof returns a GofResult that prints positive values in red and negative values in blue. GofResult behaves like a Dict, so you can still access values via string keys. Use colorize=false to keep a plain Dict output.

Examples

yobs = [-3, -5, 3, 4, 5]
ysim = [1, 2, 3, 2, 6]

gof(yobs, ysim)
Dict{String, Real} with 9 entries:
  "KGE" => -1.587134649211118
  "bias_perc" => 249.99999999999994
  "RMSE" => 3.7416573867739413
  "NSE" => 0.13366336633663367
  "MAE" => 2.8
  "bias" => 1.9999999999999998
  "R2" => 0.4347069842119348
  "R" => 0.6593231257979162
  "n" => 5
gof(1, 1)
Dict{String, Real} with 12 entries:
  "KGE" => NaN
  "intercept" => NaN
  "NSE" => NaN
  "bias_perc" => 0.0
  "slp" => NaN
  "RMSE" => 0.0
  "pvalue" => NaN
  "bias" => 0.0
  "MAE" => 0.0
  "R2" => NaN
  "R" => NaN
  "n" => 1
yobs = [1, missing, 3, 4, 5]
ysim = [1, 2, missing, 4, 6]

gof(yobs, ysim; n_small=3)
Dict{String, Real} with 9 entries:
  "KGE" => 0.768
  "bias_perc" => 10.0
  "RMSE" => 0.577
  "NSE" => 0.885
  "MAE" => 0.333
  "bias" => 0.333
  "R2" => 0.973
  "R" => 0.986
  "n" => 3.0
yobs = [1, missing, 3, 4, 5]
ysim = [1, 2, missing, 4, 6]

gof(yobs, ysim; n_small=3, colorize=false)
Dict{String, Real} with 9 entries:
  "KGE"       => 0.768
  "bias_perc" => 10.0
  "RMSE"      => 0.577
  "NSE"       => 0.885
  "MAE"       => 0.333
  "bias"      => 0.333
  "R2"        => 0.973
  "R"         => 0.986
  "n"         => 3.0

APIs

Junimo.gofFunction
gof(obs, sim; n_small=nothing, colorize=true)

Composite goodness-of-fit (GoF) metrics comparing simulated sim with observed obs. Missing values are removed pairwise: iterate zip(obs, sim) and keep only non-missing pairs.

Returns

  • A GofResult (when colorize=true) or a Dict (when colorize=false) with: KGE, NSE, R, R2, RMSE, MAE, bias, bias_perc, n

Arguments

  • obs, sim: Numeric sequences or scalars, may include missing
  • n_small: Optional number of decimal digits to round to; nothing keeps full precision
  • colorize: Whether to enable colored printing for GoF results

Formulae

  • $RMSE = \sqrt{\frac{1}{n} \sum (s_i - o_i)^2}$
  • $MAE = \frac{1}{n} \sum |s_i - o_i|$
  • $bias = \bar{s} - \bar{o}$
  • $bias\_perc = 100 \cdot bias / \bar{o}$
  • $NSE = 1 - \frac{\sum (s_i - o_i)^2}{\sum (o_i - \bar{o})^2}$
  • $KGE = 1 - \sqrt{(r-1)^2 + (\alpha-1)^2 + (\beta-1)^2}$ where $r = cor(o, s)$, $\alpha = \sigma_s / \sigma_o$, $\beta = \bar{s}/\bar{o}$

Stability and edge cases

  • When n <= 2, KGE/NSE/R/R2 return NaN
  • When $\bar{o} = 0$ or $\sigma_o = 0$, the related ratio terms return NaN

References

  • Nash, J. E., & Sutcliffe, J. V. (1970). River flow forecasting through conceptual models. Journal of Hydrology, 10(3), 282-290. doi:10.1016/0022-1694(70)90255-6
  • Gupta, H. V., Kling, H., Yilmaz, K. K., & Martinez, G. F. (2009). Decomposition of the mean squared error and NSE: Toward improved diagnostic evaluation. Water Resources Research, 45, W09417. doi:10.1029/2009WR007200
  • Willmott, C. J., & Matsuura, K. (2005). Advantages of the mean absolute error (MAE). Climate Research, 30, 79-82. doi:10.3354/cr030079
source
Junimo.GofResultType
GofResult(data; colorize=true)

Dictionary-like GoF result with colored printing. Positive values print in red and negative values in blue when colorize=true. It supports standard Dict access patterns such as res["KGE"] and pairs(res).

source