If the way mizer calculates a fundamental rate entering the model is
not flexible enough for you (for example if you need to introduce time
dependence) then you can write your own functions for calculating that
rate and use
setRateFunction() to register it with mizer.
setRateFunction(params, rate, fun) getRateFunction(params, rate) other_params(params) other_params(params) <- value
A MizerParams object
Name of the rate for which a new function is to be set.
Name of the function to use to calculate the rate.
Values for other parameters
setRateFunction(): An updated MizerParams object
getRateFunction(): The name of the registered rate function for
rate, or the list of all rate functions if called without
other_params(): A named list with all the parameters for which
you have set values.
At each time step during a simulation with the
project() function, mizer
needs to calculate the instantaneous values of the various rates. By
default it calls the
mizerRates() function which creates a list with the
For each of these you can substitute your own function. So for example if
you have written your own function for calculating the total mortality
rate and have called it
myMort and have a mizer model stored in a
MizerParams object called
params that you want to run with your new
mortality rate, then you would call
params <- setRateFunction(params, "Mort", "myMort")
In general if you want to replace a function
myVersionOfThis() you would call
params <- setRateFunction(params, "SomeRateFunc", "myVersionOfThis")
In some extreme cases you may need to swap out the entire
function for your own function called
myRates(). That you can do with
params <- setRateFunction(params, "Rates", "myRates")
Your new rate functions may need their own model parameters. These you
can store in
other_params(params). For example
other_params(params)$my_param <- 42
Note that your own rate functions need to be defined in the global environment or in a package. If they are defined within a function then mizer will not find them.