MortalityLaw: Fit Mortality Laws

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/MortalityLaw_main.R

Description

Fit parametric mortality models given a set of input data which can be represented by death counts and mid-interval population estimates (Dx, Ex) or age-specific 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.

Usage

1
2
3
4
5
6
7
MortalityLaw(x, Dx = NULL, Ex = NULL, mx = NULL, qx = NULL,
                law = NULL,
                opt.method = "LF2",
                parS = NULL,
                fit.this.x = x,
                custom.law = NULL,
                show = FALSE, ...)

Arguments

x

Vector of ages at the beginning of the age interval.

Dx

Object containing death counts. An element of the Dx object represents the number of deaths during the year to persons aged x to x+n.

Ex

Exposure in the period. Ex can be approximated by the mid-year population aged x to x+n.

mx

Life table 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. gompertz, makeham, ... To investigate all the possible options, see availableLaws function.

opt.method

How would you like to find the parameters? Specify the function to be optimize. Available options: the Poisson likelihood function poissonL; the Binomial likelihood function -binomialL; and 6 other loss functions. For more details, check the availableLF function.

parS

Starting parameters used in the optimization process (optional).

fit.this.x

Select the ages to be considered in model fitting. By default fit.this.x = x. One may want to exclude from the fitting procedure, say, the advanced ages where the data is sparse.

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: FALSE.

...

Arguments to be passed to or from other methods.

Details

Depending on the complexity of the model, one of following optimization strategies is employed:

  1. Nelder-Mead method: approximates a local optimum of a problem with n variables when the objective function varies smoothly and is unimodal. For details see optim

  2. PORT routines: provides unconstrained optimization and optimization subject to box constraints for complicated functions. For details check nlminb

  3. Levenberg-Marquardt algorithm: damped least-squares method. For details check nls.lm

Value

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 log-Likelihood.

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.

Author(s)

Marius D. Pascariu

See Also

availableLaws availableLF LifeTable ReadHMD

Examples

 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*(x-m)) (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 Heligman-Pollard 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))

Example output

sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Makeham model: mu[x] = A exp[Bx] + C
Fitted values: mx 
[1] "coefficients"    "deviance"        "df"              "fitted.values"  
[5] "goodness.of.fit" "info"            "input"           "opt.diagnosis"  
[9] "residuals"      
          A           B           C 
0.001850404 0.112720117 0.001663111 
Makeham model: mu[x] = A exp[Bx] + C
Fitted values: mx

Call: MortalityLaw(x = x, Dx = Dx, Ex = Ex, law = "makeham")

Deviance Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-0.0019 -0.0002  0.0000  0.0001  0.0003  0.0032 

Parameters:
     A      B      C 
0.0019 0.1127 0.0017 

Residual standard error: 0.004547 on 28 degrees of freedom         45          46          47          48          49          50 
0.003734302 0.003981433 0.004258052 0.004567677 0.004914246 0.005302167 
         51          52          53          54          55          56 
0.005736374 0.006222391 0.006766397 0.007375315 0.008056887 0.008819783 
         57          58          59          60          61          62 
0.009673708 0.010629521 0.011699381 0.012896894 0.014237294 0.015737628 
         63          64          65          66          67          68 
0.017416980 0.019296709 0.021400726 0.023755791 0.026391859 0.029342459 
         69          70          71          72          73          74 
0.032645120 0.036341850 0.040479669 0.045111207 0.050295374 0.056098108 
         75 
0.062593216 
         45          46          47          48          49          50 
0.003734302 0.003981433 0.004258052 0.004567677 0.004914246 0.005302167 
         51          52          53          54          55          56 
0.005736374 0.006222391 0.006766397 0.007375315 0.008056887 0.008819783 
         57          58          59          60          61          62 
0.009673708 0.010629521 0.011699381 0.012896894 0.014237294 0.015737628 
         63          64          65          66          67          68 
0.017416980 0.019296709 0.021400726 0.023755791 0.026391859 0.029342459 
         69          70          71          72          73          74 
0.032645120 0.036341850 0.040479669 0.045111207 0.050295374 0.056098108 
         75          76          77          78          79          80 
0.062593216 0.069863312 0.078000865 0.087109380 0.097304710 0.108716533 
         81          82          83          84          85          86 
0.121489998 0.135787576 0.151791121 0.169704186 0.189754614 0.212197431 
         87          88          89          90          91          92 
0.237318094 0.265436119 0.296909148 0.332137495 0.371569239 0.415705924 
         93          94          95 
0.465108937 0.520406649 0.582302408 
Makeham model: mu[x] = A exp[Bx] + C
Fitted values: mx 
         1850       1900        1950        2010
45 0.01268935 0.01195062 0.003719984 0.001385759
46 0.01310250 0.01257919 0.003967160 0.001513492
47 0.01356030 0.01326511 0.004243816 0.001653767
48 0.01406757 0.01401364 0.004553467 0.001807816
49 0.01462966 0.01483048 0.004900050 0.001976990
50 0.01525250 0.01572187 0.005287969 0.002162777
51 0.01594264 0.01669461 0.005722153 0.002366805
52 0.01670737 0.01775612 0.006208122 0.002590868
53 0.01755473 0.01891450 0.006752051 0.002836931
54 0.01849367 0.02017861 0.007360852 0.003107155
55 0.01953408 0.02155807 0.008042263 0.003403913
56 0.02068692 0.02306343 0.008804945 0.003729810
57 0.02196435 0.02470618 0.009658589 0.004087706
58 0.02337982 0.02649884 0.010614045 0.004480745
59 0.02494826 0.02845510 0.011683455 0.004912376
60 0.02668620 0.03058990 0.012880411 0.005386390
61 0.02861195 0.03291952 0.014220124 0.005906947
62 0.03074581 0.03546175 0.015719621 0.006478618
63 0.03311027 0.03823599 0.017397958 0.007106422
64 0.03573025 0.04126341 0.019276466 0.007795870
65 0.03863336 0.04456712 0.021379018 0.008553015
66 0.04185020 0.04817233 0.023732336 0.009384506
67 0.04541468 0.05210656 0.026366327 0.010297640
68 0.04936436 0.05639984 0.029314466 0.011300436
69 0.05374088 0.06108493 0.032614221 0.012401697
70 0.05859034 0.06619759 0.036307528 0.013611091
71 0.06396388 0.07177684 0.040441326 0.014939237
72 0.06991812 0.07786526 0.045068149 0.016397794
73 0.07651581 0.08450933 0.050246800 0.017999568
74 0.08382650 0.09175974 0.056043094 0.019758620
75 0.09192723 0.09967185 0.062530695 0.021690396
         1850       1900        1950        2010
55 0.01953408 0.02155807 0.008042263 0.003403913
56 0.02068692 0.02306343 0.008804945 0.003729810
57 0.02196435 0.02470618 0.009658589 0.004087706
58 0.02337982 0.02649884 0.010614045 0.004480745
59 0.02494826 0.02845510 0.011683455 0.004912376
60 0.02668620 0.03058990 0.012880411 0.005386390
61 0.02861195 0.03291952 0.014220124 0.005906947
62 0.03074581 0.03546175 0.015719621 0.006478618
63 0.03311027 0.03823599 0.017397958 0.007106422
64 0.03573025 0.04126341 0.019276466 0.007795870
65 0.03863336 0.04456712 0.021379018 0.008553015
66 0.04185020 0.04817233 0.023732336 0.009384506
67 0.04541468 0.05210656 0.026366327 0.010297640
68 0.04936436 0.05639984 0.029314466 0.011300436
69 0.05374088 0.06108493 0.032614221 0.012401697
70 0.05859034 0.06619759 0.036307528 0.013611091
71 0.06396388 0.07177684 0.040441326 0.014939237
72 0.06991812 0.07786526 0.045068149 0.016397794
73 0.07651581 0.08450933 0.050246800 0.017999568
74 0.08382650 0.09175974 0.056043094 0.019758620
75 0.09192723 0.09967185 0.062530695 0.021690396
76 0.10090338 0.10830603 0.069792054 0.023811853
77 0.11084956 0.11772818 0.077919453 0.026141618
78 0.12187060 0.12801022 0.087016184 0.028700143
79 0.13408264 0.13923061 0.097197856 0.031509892
80 0.14761440 0.15147500 0.108593866 0.034595532
81 0.16260850 0.16483684 0.121349044 0.037984152
82 0.17922297 0.17941810 0.135625496 0.041705503
83 0.19763291 0.19533009 0.151604659 0.045792256
84 0.21803237 0.21269423 0.169489611 0.050280290
85 0.24063632 0.23164305 0.189507648 0.055209006
86 0.26568303 0.25232118 0.211913179 0.060621676
87 0.29343645 0.27488645 0.236990952 0.066565819
88 0.32418910 0.29951106 0.265059678 0.073093622
89 0.35826511 0.32638296 0.296476080 0.080262393
90 0.39602360 0.35570725 0.331639425 0.088135070
Custom Mortality Law
Fitted values: mx

Call: MortalityLaw(x = x, Dx = Dx, Ex = Ex, custom.law = my_gompertz)

Deviance Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-0.0019 -0.0007 -0.0004  0.0003  0.0004  0.0085 

Parameters:
      b       M 
 0.0955 36.3412 

Residual standard error: 0.01152 on 29 degrees of freedom        85         86         87         88         89         90         91 
 0.1490000  0.1639300  0.1803560  0.1984280  0.2183108  0.2401859  0.2642528 
        92         93         94         95         96         97         98 
 0.2907314  0.3198631  0.3519139  0.3871762  0.4259719  0.4686549  0.5156148 
        99        100        101        102        103        104        105 
 0.5672802  0.6241226  0.6866606  0.7554651  0.8311639  0.9144478  1.0060768 
       106        107        108        109        110        111        112 
 1.1068873  1.2177991  1.3398244  1.4740769  1.6217817  1.7842867  1.9630750 
       113        114        115        116        117        118        119 
 2.1597781  2.3761912  2.6142892  2.8762450  3.1644492  3.4815318  3.8303867 
       120        121        122        123        124        125        126 
 4.2141973  4.6364664  5.1010474  5.6121802  6.1745293  6.7932267  7.4739185 
       127        128        129        130 
 8.2228166  9.0467555  9.9532543 10.9505857 
Heligman-Pollard model: q[x]/p[x] = A^[(x + B)^C] + D exp[-E log(x/F)^2] + G H^x
Fitted values: mx 

Full Life Table

Number of life tables: 1 
Dimension: 101 x 10 
Age intervals: [0,1) [1,2) [2,3) ...   ... [98,99) [99,100) [100,+) 

    x.int   x     mx     qx   ax    lx   dx    Lx      Tx    ex
    [0,1)   0 0.0261 0.0258  0.5 1e+05 2578 98705 7093818 70.94
    [1,2)   1 0.0022 0.0022  0.5 97422  216 97314 6995113  71.8
    [2,3)   2 0.0013 0.0013  0.5 97206  127 97142 6897799 70.96
    [3,4)   3  9e-04  9e-04  0.5 97078   92 97033 6800657 70.05
    [4,5)   4  7e-04  7e-04  0.5 96987   72 96951 6703624 69.12
    [5,6)   5  6e-04  6e-04  0.5 96914   60 96884 6606674 68.17
     <NA> ...    ...    ...  ...   ...  ...   ...     ...   ...
  [98,99)  98 0.5977 0.4499 0.45   206   92   155     264  1.29
 [99,100)  99 0.6477 0.4768 0.45   113   54    83     110  0.97
  [100,+) 100  0.702 0.5038 0.45    59   59    26      26  0.45

MortalityLaws documentation built on Sept. 16, 2020, 5:08 p.m.