Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/MortalityLaw_main.R
Fit parametric mortality models given a set of input data which can be
represented by death counts and midinterval population estimates (Dx, Ex)
or agespecific death rates (mx)
or death probabilities (qx)
.
Using the argument law
one can specify the model to be fitted.
So far more than 27 parametric models have been implemented;
check the availableLaws
function to learn about the available options. The models can be fitted under
the maximum likelihood methodology or by selecting a loss function to be
optimised. See the implemented loss function by running the
availableLF
function.
1 2 3 4 5 6 7 
x 
Vector of ages at the beginning of the age interval. 
Dx 
Object containing death counts. An element of the 
Ex 
Exposure in the period. 
mx 
Death rate in age interval [x, x+n). 
qx 
Probability of dying in age interval [x, x+n). 
law 
The name of the mortality law/model to be used. e.g.

opt.method 
How would you like to find the parameters? Specify the
function to be optimize. Available options: the Poisson likelihood function

parS 
Starting parameters used in the optimization process (optional). 
fit.this.x 
Select the ages to be considered in model fitting. By default

custom.law 
Allows you to fit a model that is not defined in the package. Accepts as input a function. 
show 
Choose whether to display a progress bar during the fitting process.
Logical. Default: 
... 
Arguments to be passed to or from other methods. 
Depending on the complexity of the model, one of following optimization strategies is employed:
NelderMead method: approximates a local optimum of a problem with n
variables when the objective function varies smoothly and is unimodal.
For details see optim
PORT routines: provides unconstrained optimization and optimization
subject to box constraints for complicated functions. For details check
nlminb
LevenbergMarquardt algorithm: damped leastsquares method.
For details check nls.lm
The output is of the "MortalityLaw"
class with the components:
input 
List with arguments provided in input. Saved for convenience. 
info 
Brief information about the model. 
coefficients 
Estimated coefficients. 
fitted.values 
Fitted values of the selected model. 
residuals 
Deviance residuals. 
goodness.of.fit 
List containing goodness of fit measures like AIC, BIC and logLikelihood. 
opt.diagnosis 
Resultant optimization object useful for checking the convergence etc. 
stats 
List containing statistical measures like: parameter correlation, standard errors, degrees of freedom, deviance, gradient matrix, QR decomposition, covariance matrix etc. 
Marius D. Pascariu
availableLaws
availableLF
LifeTable
ReadHMD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58  # Example 1: 
# Fit Makeham Model for Year of 1950.
x < 45:75
Dx < ahmd$Dx[paste(x), "1950"]
Ex < ahmd$Ex[paste(x), "1950"]
M1 < MortalityLaw(x = x, Dx = Dx, Ex = Ex, law = 'makeham')
M1
ls(M1)
coef(M1)
summary(M1)
fitted(M1)
predict(M1, x = 45:95)
plot(M1)
# Example 2: 
# We can fit the same model using a different data format
# and a different optimization method.
x < 45:75
mx < ahmd$mx[paste(x), ]
M2 < MortalityLaw(x = x, mx = mx, law = 'makeham', opt.method = 'LF1')
M2
fitted(M2)
predict(M2, x = 55:90)
# Example 3: 
# Now let's fit a mortality law that is not defined
# in the package, say a reparameterized Gompertz in
# terms of modal age at death
# hx = b*exp(b*(xm)) (here b and m are the parameters to be estimated)
# A function with 'x' and 'par' as input has to be defined, which returns at least
# an object called 'hx' (hazard rate).
my_gompertz < function(x, par = c(b = 0.13, M = 45)){
hx < with(as.list(par), b*exp(b*(x  M)) )
return(as.list(environment()))
}
M3 < MortalityLaw(x = x, Dx = Dx, Ex = Ex, custom.law = my_gompertz)
summary(M3)
# predict M3 for different ages
predict(M3, x = 85:130)
# Example 4: 
# Fit HeligmanPollard model for a single
# year in the dataset between age 0 and 100 and build a life table.
x < 0:100
mx < ahmd$mx[paste(x), "1950"] # select data
M4 < MortalityLaw(x = x, mx = mx, law = 'HP', opt.method = 'LF2')
M4
plot(M4)
LifeTable(x = x, qx = fitted(M4))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.