calibrate_model | R Documentation |
Search for the appropriate value of unknown parameters to obtain specific model results.
calibrate_model(
x,
parameter_names,
fn_values,
target_values,
initial_values = NULL,
method = c("Nelder-Mead", "BFGS", "L-BFGS-B"),
...
)
x |
Result from |
parameter_names |
Names of the parameters to calibrate. |
fn_values |
Function applied to the model that returns the values of interest as a numeric vector. |
target_values |
Values to match, same length as the
output from |
initial_values |
Optional starting values. See details. |
method |
Optimisation method ( |
... |
Optional arguments passed to
|
Parameters not being optimized are unchanged from the
values in the model run. If initial_values
is NULL
,
the initial parameter values will also be taken from the
model run.
initial_values
can be a vector or a table. In the
second case each row corresponds to a set of initial
parameter values: the calibration will be run once per
set.
Passing in multiple initial values allows (among other things) the user to check whether the calibration gets the same results from different starting points.
Multi-dimensional problems are optimized with
optimx::optimx()
, 1-dimensional problems with
stats::optimise()
(except when a method
is given).
convcode
is always NA
with stats::optimise()
.
Running calibrate_model()
does not change the model
parameters; the user must create a new model and run it
if desired.
See also vignette("k-calibration")
.
A data frame in which each row has the calibrated
values of parameters given in parameter_names
, for
the corresponding row of initial_values
, along with
the convergence code for each run.
param <- define_parameters(p = 0.8)
mat <- define_transition(
p, C,
0, 1
)
mod <- define_strategy(
transition = mat,
A = define_state(cost=10, effect = 0.5),
B = define_state(cost = 5, effect = 0.8)
)
res_mod <- run_model(
mod = mod,
parameters = param,
init = c(1000L, 0L),
cycles = 10,
cost = cost,
effect = effect,
method = "end"
)
f <- function(x) {
dplyr::filter(
get_counts(x),
state_names == "A" & model_time == 10
)$count
}
f(res_mod)
#'\dontrun{
#'calibrate_model(
#' res_mod,
#' parameter_names = "p",
#' fn_values = f,
#' target_values = 130,
#' initial_values = data.frame(p = c(0.5, 0.9)),
#' lower = 0, upper = 1
#')
#'}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.