buildTsObjective {hydromad} | R Documentation |
Generate objective functions with temporal aggregation, data transformation and an optional reference model.
buildTsObjective(Q, groups = NULL, FUN = sum, ..., ref = NULL, boxcox = FALSE, start = NULL)
Q |
observed data, typically a |
groups |
an optional grouping variable, of the same length as |
FUN, ... |
the aggregation function (and any extra arguments) to use on each
group when |
ref |
output from a reference model correponding to |
boxcox, start |
if |
buildTsObjective
returns a function
, which can be
passed arguments Q, X, ...
(the standard signature for hydromad
objective functions). The Q
argument is ignored since it was
already specified directly to buildTsObjective
: i.e. the
returned function is only valid on the same dataset Q
with
corresponding fitted values X
. Further arguments to the
returned function will be passed on to nseStat
(therefore the objective function is to be maximised, not minimised).
If boxcox = TRUE
was specified, the estimated Box-Cox power can
be extracted from the returned function f
by
environment(f)$lambda
and similarly for the offset value
start
.
Felix Andrews felix@nfrac.org
nseStat
,
eventseq
,
cut.Date
,
hydromad.stats
data(Cotter) dat <- window(Cotter, start = "1990-01-01", end = "1993-01-01") ## use Box-Cox transform with parameters estimated from Q objfun <- buildTsObjective(dat$Q, boxcox = TRUE) objfun(X = dat$Q + 10) ## extract the estimated Box-Cox parameters lambda <- environment(objfun)$lambda start <- environment(objfun)$start require(car) qqmath(~ bcPower(dat$Q + start, lambda)) ## in this case the result is the same as: nseStat(bcPower(dat$Q + start, lambda), bcPower(dat$Q + 10 + start, lambda)) ## use monthly aggregation and log transform (Box-Cox lambda = 0) objfun <- buildTsObjective(dat$Q, groups = cut(time(dat), "months"), FUN = sum, boxcox = 0) objfun(X = dat$Q + 10)