Calculate objective function value for a fitted model.

objFunVal(x, objective, ...)

# S3 method for default
objFunVal(x, objective = hydromad.getOption("objective"), ..., nan.ok = FALSE)

# S3 method for hydromad
objFunVal(
  x,
  objective = hydromad.getOption("objective"),
  ...,
  all = FALSE,
  nan.ok = FALSE
)

# S3 method for runlist
objFunVal(x, objective = list(hydromad.getOption("objective"), mean), ...)

Arguments

x

object from which to calculate stats. For the hydromad method, this should be a fitted hydromad model object, i.e. it must have specific parameter values, not ranges. For the default method, this should be a matrix-like object with named columns Q, X and optionally U and P.

objective

the objective function, or a list of objective functions. See Details.

For a runlist, either: 1) a function taking a runlist as first argument or 2) a list with two elements, the first as for hydromad and default, the second a function that aggregates the objectives to a single value.

...

ignored for hydromad and default, passed to objFunVal.hydromad for runlist

nan.ok

by default, an error is thrown if the result is NaN. Set this argument to TRUE to suppress the error.

all

passed to fitted and observed.

Value

the objective function value, or a list of objective function values. They must be numeric and of length one; anything else is an error.

Details

The objective function is given as a function with arguments Q, X and ...{}, and optionally other arguments. Q and X represent observed and modelled flow, respectively. It should return a single numeric value.

For more advanced use it may also refer to arguments U (modelled effective rainfall), or P (observed rainfall), and more generally it may refer to model, and so may extract other items of data, parameters, etc.

The default (unless changed in hydromad.options("objective")) is a weighted sum of the R Squared (coefficient of determination) of square-root transformed data, and the relative bias.

See hydromad.stats for examples of how to specify other fit statistics.

See also

hydromad.stats, hydromad.object

Author

Felix Andrews felix@nfrac.org

Examples


dat <- data.frame(Q = rnorm(10), X = rnorm(10))
objFunVal(dat, hmadstat("RMSE"))
#> [1] 1.560361