init_val.Rd
Helper for setting initial parameter value
g3_init_val(
param_template,
name_spec,
value = NULL,
spread = NULL,
lower = if (!is.null(spread)) min(value * (1-spread), value * (1+spread)),
upper = if (!is.null(spread)) max(value * (1-spread), value * (1+spread)),
optimise = !is.null(lower) & !is.null(upper),
parscale = if (is.null(lower) || is.null(upper)) NULL else 'auto',
random = NULL,
auto_exponentiate = TRUE)
A glob-like string to match parameter names, see Details
Numeric value / vector of values to set for value / 'value' column in template. Original value left if NULL
Shortcut for setting lower & upper.
Numeric value / vector of values to set for 'lower' column in template. Original value left if NULL
Numeric value / vector of values to set for 'upper' column in template. Original value left if NULL
Boolean value to set for 'optimise' column in template. Default is true iff both lower and upper are non-NULL. Original value left if NULL
Numeric value / vector of values to set for 'parscale' column in template.
Default (auto
) is difference between lower & upper (or NULL if they're not set).
Original value left if NULL
Boolean value to set for 'random' column in template. Original value left if NULL
If TRUE, will implicitly match parameters ending with "_exp",
and if this is the case log
all value/lower/upper values
name_spec is a glob (or wildcard) matching parameters.
It is a string separated by .
, where each part can be:
A wildcard matching anything (*
), or a matching anything with a prefix, e.g. m*
A wildcard matching any number (#
), or a matching a number with a prefix, e.g. age*
A range of numbers, e.g. [1979-1984]
A choice of options can be separated with |
, e.g. init|rec
or [1979-1984]|[2000-2003]
A new parameter template list/table containing modifications
# A parameter template, would already be got via. attr(g3_to_tmb(...), "parameter_template")
pt <- data.frame(
switch = c(
paste0('fish.init.', 1:9),
paste0('fish.rec.', 1990:2000),
'fish.M'),
value = NA,
lower = NA,
upper = NA,
parscale = NA,
optimise = FALSE,
random = FALSE)
# Set all fish.init.# parameters to optimise
pt <- g3_init_val(pt, 'fish.init.#', 4, spread = 8)
# Set a fixed value for any .M
pt <- g3_init_val(pt, '*.M', value = 0.3, optimise = FALSE)
# Set a fixed value for a range of recruitment years, optimise the rest
pt |>
g3_init_val('*.rec.#', value = 4, lower = 0, upper = 10) |>
g3_init_val('*.rec.[1993-1996]', value = 0, optimise = FALSE) |>
identity() -> pt
pt
#> switch value lower upper parscale optimise random
#> 1 fish.init.1 4.0 -28 36 64 TRUE FALSE
#> 2 fish.init.2 4.0 -28 36 64 TRUE FALSE
#> 3 fish.init.3 4.0 -28 36 64 TRUE FALSE
#> 4 fish.init.4 4.0 -28 36 64 TRUE FALSE
#> 5 fish.init.5 4.0 -28 36 64 TRUE FALSE
#> 6 fish.init.6 4.0 -28 36 64 TRUE FALSE
#> 7 fish.init.7 4.0 -28 36 64 TRUE FALSE
#> 8 fish.init.8 4.0 -28 36 64 TRUE FALSE
#> 9 fish.init.9 4.0 -28 36 64 TRUE FALSE
#> 10 fish.rec.1990 4.0 0 10 10 TRUE FALSE
#> 11 fish.rec.1991 4.0 0 10 10 TRUE FALSE
#> 12 fish.rec.1992 4.0 0 10 10 TRUE FALSE
#> 13 fish.rec.1993 0.0 0 10 10 FALSE FALSE
#> 14 fish.rec.1994 0.0 0 10 10 FALSE FALSE
#> 15 fish.rec.1995 0.0 0 10 10 FALSE FALSE
#> 16 fish.rec.1996 0.0 0 10 10 FALSE FALSE
#> 17 fish.rec.1997 4.0 0 10 10 TRUE FALSE
#> 18 fish.rec.1998 4.0 0 10 10 TRUE FALSE
#> 19 fish.rec.1999 4.0 0 10 10 TRUE FALSE
#> 20 fish.rec.2000 4.0 0 10 10 TRUE FALSE
#> 21 fish.M 0.3 NA NA NA FALSE FALSE