1

I am trying to reproduce one of models evolved on the base of Lee-Carter model by use of RStudio. Because I am still pretty fresh in this software, my question is not really sophisticated.

Applying MLE with Poisson distribution, I got final solution: $\alpha_x + \beta_x \, \kappa_t = \log(D_{x,t} / E_{x,t})$ with x as number of ages (for instance from i = 0 to 90) and with t as year (for instance from j = 1970 to 2016). Then $D_{x,t}$ and $E_{x,t}$ are matrix x = 91 (rows) times t = 47 (columns), number of cells= 4277 in which every cell is noted either by $D_{i,j}$ or $E_{i,j}$. These values are earlier determined and we will keep them as given values since they could be estimated by singular value decomposition, what I have managed to do earlier.

As in Lee-Carter model one imposes consecutive restraints: all kappas in vector of parameters $\sum_t \kappa_t = 0$ and all betas in vector of parameters $\sum_x \beta_x = 1$, one gets a constrained problem.

Moreover, one can notice that number of parameters to be changed equals to $2x + t$ as $\alpha_i$ is not time-dependent, what gives in my case 229 (91*2 + 47) parameters. In that way one wants to minimize the difference between LHS (to be adjusted) and RHS (earlier calculated deterministic values).

I have tried many functions not finding the solution. My last version of code follows:

ages <- 91 #in description called "x"
years <-47 #in description called "t"
DX_Expo_POLF <- matrix(0,ages, years) #deaths are divided by exposure and taken into logarithm


#the operation is repeated for whole matrix
for (i in 1:ages) {
  for (j in 1:years) {
    DX_Expo_POLF[i,j] <- log(DX_PolandF[i,j]/Expo_PolandF[i,j])
  }
}

#difference between LHS and RHS is to be minimised. Left - earlier determined values
    obj_POLF <- as.vector(abs(DX_Expo_POLF -  (rep(main_aPOLF,years) + main_bPOLF %*% main_kPOLF)))

mat_POLF <- matrix(0,2, ages ) #first parameter - beta, second one - kappa

for (i in 1:ages) {
    mat_POLF[1,i] <- main_bPOLF[i,1]
}

for (i in 1:years) {
  mat_POLF[2,i] <- main_kPOLF[1,i]
}

dir_POLF   <- rep("==", 2)           # constraint directions
rhs_POLF   <- c(1,0)                 # constraint upper-bounds

opt_POLF <- Rglpk_solve_LP(obj = obj_POLF, mat = mat_POLF, dir = dir_POLF, rhs = rhs_POLF, max = FALSE)

opt_POLF.main_kPOLF <- matrix(opt_POLF$solution, 1, years) 
opt_POLF.mat_POLF <- matrix(opt_POLF$solution, ages, years) 

where I tried to minimize absolute difference between both matrices by keeping vectors restrained. Repeating, only vectors $\alpha_x , \beta_x , \kappa_t$ should be changed.

Basically my question is: what function and specification should I use?

Excuse me if question is trivial.

Glen_b
  • 257,508
  • 32
  • 553
  • 939
JJ-23
  • 11
  • 2
  • You appear to be using $x$ to denote two distinct things -- *age* and *the number of ages* (length of the age-dimension); this is problematic. – Glen_b Feb 27 '19 at 12:16
  • @Glen_b Excuse me for confusing definition, in this model ages is not a vector but just a number of ages, so the integer, similarly years. – JJ-23 Feb 27 '19 at 15:38
  • When you write $\alpha_x$, or $D_{x,t}$, what does the $x$ stand for? Is not $\alpha_x$ a vector, with a value for each age (where age is there represented by $x$)? – Glen_b Feb 27 '19 at 21:03
  • @Glen_b yes, I will correct the description of the problem. – JJ-23 Feb 27 '19 at 21:51

0 Answers0