Given a set of parameters (on the log scale), this function evaluates the chosen loss function or negative log-likelihood by comparing observed mortality values (Dx/Ex, mx, or qx) against the hazard rates predicted by the specified mortality law.
objective_fun(par, x, Dx, Ex, mx, qx, law, opt.method, custom.law)A scalar loss value to be minimised.
Parameter vector on the log scale.
Numeric vector of ages at the beginning of each age interval.
For a full life table, use single-year ages (e.g., 0:110).
For an abridged life table, use the lower bound of each interval
(e.g., c(0, 1, 5, 10, ..., 110)).
Death counts. Each element represents the total number of
deaths during the calendar year to persons aged x to
x + n (where n is the length of the age interval).
Must be provided together with Ex.
Exposure-to-risk in the period. This is usually approximated
by the mid-year population aged x to x + n. Must be
provided together with Dx.
Age-specific death rate in the age interval [x, x+n).
Defined as Dx / Ex.
Probability of dying within the age interval [x, x+n).
The name of the mortality law to be used (e.g., "gompertz",
"makeham"). Run availableLaws to see all options.
The function to optimise. Available options:
"poissonL": Poisson log-likelihood.
"binomialL": Binomial log-likelihood.
"LF1": Squared relative error (1 - mu/nu)^2.
"LF2": Squared log-ratio log(mu/nu)^2.
"LF3": Chi-squared-type ((nu - mu)^2)/nu.
"LF4": Squared error (nu - mu)^2.
"LF5": Deviance-type (nu - mu) * log(nu/mu).
"LF6": Absolute error abs(nu - mu).
See availableLF for details.
A user-defined function for fitting a model not included
in the package. The function must accept arguments x (age vector)
and par (named parameter vector) and return a list containing at
least an element named hx (the hazard or force of mortality). See
the examples below.
Parameters are transformed back to the original scale via exp(par)
when calling the mortality law function. Infinite hazard values are capped
to 1, and large penalties are applied for missing or out-of-range values
to guide the optimiser away from invalid regions.