Learn R Programming

MortalityLaws (version 2.2.0)

objective_fun: Objective function to minimise during optimisation

Description

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.

Usage

objective_fun(par, x, Dx, Ex, mx, qx, law, opt.method, custom.law)

Value

A scalar loss value to be minimised.

Arguments

par

Parameter vector on the log scale.

x

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)).

Dx

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.

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.

mx

Age-specific death rate in the age interval [x, x+n). Defined as Dx / Ex.

qx

Probability of dying within the age interval [x, x+n).

law

The name of the mortality law to be used (e.g., "gompertz", "makeham"). Run availableLaws to see all options.

opt.method

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.

custom.law

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.

Details

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.