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
  "n" => 5
  "RMSE" => 3.7416573867739413
  "NSE" => 0.13366336633663367
  "MAE" => 2.8
  "bias" => 1.9999999999999998
  "R2" => 0.4347069842119348
  "R" => 0.6593231257979162
  "PBIAS" => 249.99999999999994
gof(1, 1)
Dict{String, Real} with 12 entries:
  "KGE" => NaN
  "intercept" => NaN
  "n" => 1
  "NSE" => NaN
  "slp" => NaN
  "RMSE" => 0.0
  "pvalue" => NaN
  "bias" => 0.0
  "MAE" => 0.0
  "R2" => NaN
  "R" => NaN
  "PBIAS" => 0.0
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
  "n" => 3.0
  "RMSE" => 0.577
  "NSE" => 0.885
  "MAE" => 0.333
  "bias" => 0.333
  "R2" => 0.973
  "R" => 0.986
  "PBIAS" => 10.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
  "n"     => 3.0
  "RMSE"  => 0.577
  "NSE"   => 0.885
  "MAE"   => 0.333
  "bias"  => 0.333
  "R2"    => 0.973
  "R"     => 0.986
  "PBIAS" => 10.0

APIs

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

Compute goodness-of-fit (GOF) metrics comparing simulated sim with observed obs.

Inputs

  • obs: observed values, scalar or array, may include missing
  • sim: simulated values, scalar or array, may include missing
  • n_small: number of decimal digits to round to; nothing keeps full precision
  • colorize: whether to return a colored GofResult for pretty printing

Outputs

  • result: GofResult (when colorize=true) or Dict{String, Float64} (when colorize=false) with keys: KGE, NSE, R, R2, RMSE, MAE, bias, PBIAS, n

Rules for stability:

  • Missing values are removed pairwise via zip(obs, sim).
  • If n <= 2, KGE, NSE, R, and R2 return NaN.
  • If mean(obs) == 0 or std(obs) == 0, ratio-based terms return NaN.

Formula

  • $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}$

References

  • Nash, J. E., and 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., and 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., and 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