dev/mig_resid_singleTest.R

# # #' Estimate net migration using residual methods: stock change,
# # #' time even flow and cohort even flow
# # #'
# # #' @details
# # #'
# # #' 1. The stock method (\code{mig_resid_stock}) is the difference in stocks that
# # #' survive between t and t+5, and the first age group is based on the difference
# # #' with the surviving births by sex.  It provides net migrants by lexis cohort
# # #' parallelograms, and basically such info gets used as end-period migration
# # #' since the migrants don't get exposed to mortality within the period.
# # #'
# # #' 2. The time even flow (\code{mig_resid_time}) method uses the result from
# # #' the first option, but splits it back into lexis period squares and assumes
# # #' that half of the net migrants get exposed to the mortality risk during this
# # #' period. Such info can get used as evenly distributed migration by period,
# # #' but the assumptions lead to zig-zag age patterns that are highly implausible.
# # #'
# # #' 3. The cohort even flow (\code{mig_resid_cohort}) method provides the most
# # #' meaningful pattern of net migration by age consistent by cohort and assumes
# # #' an evenly distribution within the 5-year period, and half of the migrants
# # #' get exposed both fertility and mortality within this period.
# # #'
# # #' @param pop_m_mat A \code{numeric} matrix with population counts. Rows should
# # #' be ages and columns should be years. Only five year age groups are supported.
# # #' See examples.
# # #'
# # #' @param pop_f_mat A \code{numeric} matrix with population counts. Rows should
# # #' be ages and columns should be years. Only five year age groups are supported.
# # #' See examples.
# # #'
# # #' @param sr_m_mat A \code{numeric} matrix with survival rates for males. Rows
# # #' should be ages and columns should be years. ** This matrix should have
# # #' one column less than \code{pop_m_mat} and \code{pop_f_mat}. For example,
# # #' if the last year in these matrices is 2050, then the last year in
# # #' \code{sr_m_mat} should be 2045. **
# # #'
# # #' @param sr_f_mat A \code{numeric} matrix with survival rates for females. Rows
# # #' should be ages and columns should be years. ** This matrix should have
# # #' one column less than \code{pop_m_mat} and \code{pop_f_mat}. For example,
# # #' if the last year in these matrices is 2050, then the last year in
# # #' \code{sr_f_mat} should be 2045. **.
# # #'
# # #' @param asfr_mat A \code{numeric} matrix with age specific fertility rates.
# # #' Rows should be ages and columns should be years. ** This matrix should have
# # #' one column less than \code{pop_m_mat} and \code{pop_f_mat}. For example,
# # #' if the last year in these matrices is 2050, then the last year in
# # #' \code{asfr_mat} should be 2045**. This row will usually have fewer age groups
# # #' (rows) than in the population matrices or survival matrices, so the user
# # #' needs to supply the specific ages in the \code{ages_asfr} argument.
# # #'
# # #' @param srb_vec A \code{numeric} vector of sex ratios at birth for every year.
# # #' The years should be the same as the years in \code{sr_m_mat},
# # #' \code{sr_f_mat}, and \code{asfr_mat}.
# # #'
# # #' @param ages A \code{numeric} vector of ages used in the rows in
# # #' \code{pop_m_mat}, \code{pop_f_mat}, \code{sr_m_mat}, \code{sr_f_mat}.
# # #'
# # #' @param ages_asfr A \code{numeric} vector of ages used in the rows in
# # #' \code{asfr_mat}.
# # #'
# # #' @return A list with two matrices. One is for males (called `mig_m`) and the
# # #' other for females (called `mig_f`). Both matrices contain net migration
# # #' estimates by age/period using one of the three methods.
# # #'
# # #' @examples
# # #'
# # #' ################ Stock change method #####################
# # #'
# # #' # Vector of population for males
# # #' pop_m <-
# # #'   c(38,45,51,55,59,61,62,62,62,61,60,59,58,56,54,52,51,51,51,51,51,52,54,55,57,59,61,62,63,64,65# # ,65,65,65,65,65,64,63,62,61,60,60,59,59,59,58,59,60,62,64,66,67,67,65,63,61,59,56,53,49,46,43,41,40# # ,39,38,37,36,35,35,34,34,34,33,33,33,32,30,28,25,23,20,18,16,15,13,11,9,8,6,5,4,3,2,1,1,1,1,0,0,0,
# # #'     36,43,49,53,57,59,61,62,62,62,62,61,59,58,56,54,53,51,51,51,51,52,52,54,55,57,59,61,62,63,64# # ,65,65,65,65,65,65,64,63,62,61,60,59,59,59,59,58,58,60,62,64,66,67,66,64,63,61,59,56,52,49,45,42,41# # ,39,38,37,36,35,35,34,34,33,33,32,32,31,30,28,26,24,21,19,17,15,13,11,9,8,6,5,3,3,2,1,1,1,0,0,0,0,
# # #'     38,38,44,49,53,56,59,61,62,63,62,62,61,60,58,56,55,53,52,51,52,52,52,53,54,56,58,60,61,62,63# # ,64,65,66,66,65,65,65,64,63,62,61,60,59,59,59,58,58,58,60,62,64,66,67,66,64,62,61,58,55,52,49,45,42# # ,40,39,38,36,35,34,34,33,33,32,32,31,30,30,29,27,24,22,19,17,15,13,11,10,8,7,5,4,3,2,2,1,1,0,0,0,0,
# # #'     43,45,40,44,48,52,55,58,61,63,63,63,62,61,60,58,57,55,53,52,52,52,52,53,53,55,56,58,60,61,63# # ,64,64,65,66,66,65,65,65,64,63,62,61,60,59,59,59,58,58,58,60,62,64,65,66,66,64,62,60,58,55,51,48,44# # ,41,39,38,37,36,34,34,33,32,32,31,30,30,29,28,27,25,22,20,17,15,13,12,10,8,7,6,4,3,2,2,1,1,0,0,0,0,
# # #'     50,48,47,41,45,48,52,55,58,61,63,64,63,62,61,60,58,57,55,53,52,52,52,53,53,54,55,57,59,60,62# # ,63,64,65,65,66,66,65,65,65,64,63,62,61,60,59,59,58,58,58,58,59,61,63,65,66,65,63,62,60,57,54,51,47# # ,44,41,39,37,36,35,34,33,32,31,30,30,29,28,27,26,25,23,21,18,16,13,11,10,8,7,6,4,3,2,2,1,1,1,0,0,0,
# # #'     56,51,47,46,43,45,48,51,54,58,61,64,64,63,62,61,60,59,57,55,54,52,52,53,53,54,55,56,57,59,61# # ,62,63,64,65,66,66,66,66,65,65,64,63,62,61,60,59,59,58,58,58,58,59,61,63,65,66,65,63,61,59,57,54,50# # ,47,43,40,38,37,35,34,33,32,31,30,29,29,28,27,26,25,23,21,19,16,14,12,10,8,7,5,4,3,2,2,1,1,1,0,0,0,
# # #'     60,53,49,46,45,45,46,48,51,54,57,62,64,65,64,63,62,61,59,57,56,54,53,53,53,54,54,55,56,58,59# # ,61,62,64,64,65,66,66,66,66,65,65,64,63,62,61,60,59,59,58,58,58,58,59,61,63,65,65,65,63,61,59,57,53# # ,50,46,43,40,38,36,35,33,32,31,30,29,28,27,26,25,24,23,22,19,17,15,12,10,8,7,5,4,3,2,1,1,1,1,0,0,0,
# # #'     62,59,53,49,47,45,45,46,48,51,54,58,62,65,65,64,63,62,61,60,58,57,55,54,54,54,54,55,56,57,58# # ,60,61,63,64,65,65,66,67,66,66,65,65,64,63,62,61,60,59,58,58,58,57,57,59,61,62,64,65,64,62,60,58,56# # ,53,49,46,42,39,37,35,34,32,31,30,29,28,27,26,25,24,22,21,20,18,15,13,11,9,7,6,4,3,3,2,1,1,1,0,0,0,
# # #'     61,56,58,53,50,48,46,46,46,48,51,55,59,63,66,66,65,64,63,62,60,59,58,56,55,55,55,55,56,56,57# # ,59,60,62,63,64,65,66,67,67,67,66,65,65,64,63,62,61,60,59,58,58,57,57,57,58,60,62,64,65,64,62,60,57# # ,55,52,48,45,41,38,36,35,33,31,30,29,28,27,26,25,23,22,21,19,18,16,14,11,9,7,6,5,4,3,2,2,1,1,0,0,0,
# # #'     60,57,54,57,53,51,49,48,47,47,48,51,55,59,64,67,67,66,65,64,62,61,60,59,57,56,56,56,56,56,57# # ,58,60,61,62,64,65,66,66,67,68,67,67,66,65,64,63,62,61,60,59,58,58,57,57,57,58,60,62,64,64,63,61,59# # ,57,54,51,48,44,41,37,35,34,32,31,29,28,27,25,24,23,22,20,19,18,16,14,12,10,8,6,5,4,3,2,2,1,1,0,0,0# # ,
# # #'     59,57,56,55,56,53,51,50,49,48,47,48,51,55,60,65,68,68,67,66,64,63,62,61,60,58,57,57,57,57,57# # ,58,59,60,61,63,64,65,66,67,68,68,68,67,66,65,64,63,62,61,60,59,58,58,57,56,56,58,60,62,63,64,63,61# # ,59,56,54,50,47,44,40,37,34,33,31,30,28,27,25,24,23,22,20,19,17,16,14,12,10,8,6,5,4,3,2,1,1,1,0,0,0# # ,
# # #'     57,58,58,57,56,55,53,52,51,50,49,47,48,51,56,60,65,69,69,68,66,65,64,63,62,61,60,59,58,58,58# # ,58,58,59,61,62,63,64,66,67,68,68,69,68,67,66,65,63,62,62,61,60,59,58,58,57,56,56,57,59,61,63,64,63# # ,60,58,56,53,50,46,43,39,36,34,32,30,29,27,26,24,23,22,20,19,17,15,14,12,10,8,6,5,4,3,2,1,1,1,0,0,0# # ,
# # #'     57,58,59,58,57,56,55,54,52,51,50,49,48,48,51,57,61,67,70,70,69,67,66,65,64,63,62,60,59,59,59# # ,59,59,59,60,61,62,64,65,66,67,68,69,69,69,67,66,65,63,62,62,61,60,59,58,57,57,56,56,57,59,61,63,63# # ,62,60,57,55,52,49,45,42,38,35,33,31,29,27,26,24,23,21,20,19,17,15,14,12,11,9,7,5,4,3,2,1,1,1,0,0,0# # ,
# # #'     56,59,59,59,59,58,57,55,54,53,51,50,49,48,48,52,57,62,68,71,71,70,68,67,65,64,63,62,61,60,60# # ,59,59,59,59,60,62,63,64,65,66,67,68,69,69,69,67,66,65,63,62,62,61,60,59,58,57,56,55,55,56,58,60,62# # ,63,62,59,56,54,51,47,44,41,37,34,31,30,28,26,24,23,21,20,19,17,16,14,12,11,9,8,6,4,3,3,2,1,1,1,0,0# # ,
# # #'     56,59,60,60,60,59,58,57,56,54,53,52,51,50,48,49,53,58,63,69,72,73,71,69,68,66,65,64,63,62,61# # ,60,60,60,60,60,61,62,63,64,66,67,68,69,69,70,69,68,66,65,63,62,61,61,60,59,58,57,56,55,54,56,58,60# # ,62,62,61,58,56,53,50,46,43,39,36,33,30,28,27,25,23,21,20,18,17,15,14,12,11,9,8,6,5,3,3,2,1,1,1,0,0# # ,
# # #'     57,59,61,62,61,61,60,59,57,56,54,53,52,51,50,49,49,53,59,64,70,73,74,72,70,69,67,66,65,64,63# # ,62,61,61,60,60,60,61,62,63,65,66,67,68,69,70,70,69,68,66,65,63,62,61,60,60,59,58,57,55,54,54,55,57# # ,59,61,62,60,58,55,52,49,45,42,38,35,31,29,27,25,23,22,20,18,17,15,14,12,11,9,8,6,5,4,2,2,1,1,1,0,0# # ,
# # #'     57,59,61,62,62,62,61,60,59,57,56,55,53,52,51,50,49,50,54,59,65,71,74,75,73,71,69,68,67,66,64# # ,63,62,61,61,61,60,60,61,62,64,65,66,67,68,69,70,70,69,68,66,64,63,62,61,60,59,58,57,56,55,54,53,55# # ,57,59,61,61,60,57,54,51,47,44,41,37,33,30,28,26,24,22,20,19,17,15,14,12,11,9,7,6,5,4,2,1,1,1,1,0,0# # ,
# # #'     58,58,60,61,62,62,62,61,60,59,58,56,55,54,53,52,51,50,51,54,60,66,71,75,75,73,72,70,68,67,66# # ,65,64,63,62,61,61,61,61,62,63,64,65,66,67,68,69,70,70,69,68,66,64,63,62,61,60,59,58,57,56,55,53,53# # ,54,56,58,60,61,59,56,53,50,46,43,39,36,32,29,26,24,23,21,19,17,15,14,12,11,9,8,6,5,4,3,2,1,1,1,0,0# # ,
# # #'     60,61,59,60,61,62,62,62,61,60,59,58,57,55,54,53,52,51,50,51,55,61,66,72,76,76,74,72,71,69,68# # ,67,65,64,63,62,62,61,61,61,62,63,64,65,66,67,68,69,70,70,69,68,66,64,63,62,61,60,59,58,57,55,54,53# # ,52,53,56,57,59,60,58,55,52,48,45,42,38,35,31,28,25,23,21,19,17,15,14,12,11,9,8,6,5,4,3,3,2,1,1,0,0# # ,
# # #'     61,61,61,59,60,61,61,61,61,61,61,60,58,57,56,55,54,53,52,51,52,56,62,67,73,77,77,75,73,71,69# # ,68,67,66,64,63,62,62,62,61,61,62,63,64,65,66,67,68,69,70,70,69,68,66,64,63,61,60,59,59,58,56,55,54# # ,52,52,53,55,57,58,59,57,54,50,47,44,40,37,33,30,26,24,22,19,18,16,14,12,10,9,8,7,5,4,3,3,2,1,1,0,0# # ,
# # #'     62,62,62,61,60,61,61,61,61,61,61,61,60,58,57,56,55,54,53,53,52,53,57,62,68,74,77,77,75,74,72# # ,70,68,67,66,65,64,63,62,62,61,61,62,63,64,65,66,67,68,69,70,70,69,67,66,64,62,61,60,59,58,57,56,55# # ,53,52,51,52,54,56,57,58,56,53,49,46,43,39,36,32,28,25,22,20,18,16,14,12,11,9,8,7,5,4,3,2,2,1,1,0,0# # )
# # #' # Vector of population for females
# # #' pop_f <-
# # #'   c(36,43,48,53,56,58,59,59,59,58,57,56,55,53,51,50,48,48,49,49,49,50,52,53,55,57,59,60,60,61,62# # ,62,62,62,62,61,61,60,59,59,58,57,57,57,57,57,57,59,61,63,65,66,65,63,61,59,57,55,52,49,46,44,42,42# # ,41,40,40,40,40,40,40,40,41,41,41,42,41,40,38,36,33,31,29,27,25,23,21,19,16,14,11,10,8,6,4,3,3,2,1# # ,1,1,
# # #'     34,41,46,50,54,56,58,59,59,59,58,57,56,55,53,51,50,48,48,49,49,50,50,52,54,55,57,59,60,61,61# # ,62,62,62,62,62,61,61,60,59,59,58,57,57,57,57,56,57,59,61,63,65,66,65,63,61,59,57,54,51,49,46,43,42# # ,41,41,40,40,40,39,40,40,40,40,40,41,41,40,39,36,34,32,29,27,25,23,21,19,17,14,11,9,8,6,4,3,2,2,1,1# # ,1,
# # #'     36,36,41,46,50,53,56,58,59,60,59,59,58,56,55,53,52,50,49,49,49,50,50,51,52,54,56,58,59,60,61# # ,62,62,63,63,62,62,62,61,60,60,59,58,57,57,57,57,57,57,59,61,63,65,66,65,63,61,59,57,54,51,48,45,43# # ,42,41,40,40,39,39,39,39,39,39,39,39,39,39,39,37,35,32,30,27,25,23,21,19,17,15,12,10,8,7,5,3,2,2,1# # ,1,1,
# # #'     41,43,38,42,46,50,53,56,58,60,60,60,59,58,57,55,54,52,50,49,49,50,50,51,52,53,55,56,58,60,61# # ,61,62,63,63,63,63,62,62,61,60,60,59,58,57,57,57,57,56,57,58,61,63,65,65,65,63,61,59,56,54,51,48,45# # ,43,41,41,40,39,39,38,38,38,38,38,38,38,38,38,37,35,33,30,28,25,23,21,19,17,15,13,10,8,7,6,4,3,2,1# # ,1,1,
# # #'     47,45,44,39,42,46,49,52,55,58,60,60,60,59,58,57,55,54,52,51,50,50,50,51,51,52,53,55,57,58,60# # ,61,61,62,63,63,63,63,62,62,61,60,60,59,58,57,57,57,57,56,57,58,60,62,64,65,64,62,60,58,56,53,51,48# # ,45,42,41,40,39,39,38,38,38,37,37,37,37,37,37,37,36,34,31,29,26,23,21,19,17,15,13,11,8,6,5,4,3,2,1# # ,1,1,
# # #'     53,48,45,43,41,43,46,49,52,55,58,61,61,60,59,58,57,56,54,53,51,50,50,51,51,52,53,54,55,57,59# # ,60,61,62,62,63,63,63,63,62,62,61,61,60,59,58,57,57,57,57,56,57,58,60,62,64,65,64,62,60,58,56,53,50# # ,47,44,42,40,40,39,38,38,37,37,37,37,36,36,36,36,35,34,32,29,27,24,21,19,17,14,13,11,9,6,5,4,3,2,1# # ,1,1,
# # #'     57,50,46,43,42,42,44,46,48,51,55,59,61,61,60,59,58,57,56,55,53,52,51,51,51,52,52,53,54,56,58# # ,59,61,61,62,63,63,64,63,63,63,62,61,61,60,59,58,57,57,57,57,56,57,58,60,62,64,65,64,62,60,58,56,53# # ,50,47,44,42,40,39,38,38,37,37,36,36,36,36,35,35,34,34,33,31,28,25,22,19,17,15,12,10,9,7,5,3,3,2,1# # ,1,1,
# # #'     58,56,50,47,44,43,43,44,45,48,51,55,59,62,62,61,60,59,58,57,55,54,52,51,51,52,52,53,54,55,56# # ,58,59,61,62,62,63,64,64,64,63,63,62,61,61,60,59,58,57,57,57,57,56,56,58,60,62,64,65,64,62,59,57,55# # ,52,49,47,44,41,40,39,38,37,36,36,35,35,35,34,34,33,32,32,31,28,25,23,20,17,15,13,10,9,8,6,4,3,2,2# # ,1,1,
# # #'     58,53,55,50,47,45,44,44,44,45,48,52,56,60,63,63,62,61,60,59,57,56,55,53,52,52,53,53,53,54,55# # ,57,58,60,61,62,63,64,64,64,64,64,63,62,61,60,60,59,58,58,57,57,56,56,56,58,60,62,64,65,64,61,59,57# # ,54,52,49,46,43,41,39,38,37,36,36,35,35,34,34,33,32,32,31,30,28,26,23,20,17,15,13,11,9,7,6,5,3,2,2# # ,1,1,
# # #'     57,54,51,54,51,48,46,45,45,44,45,48,52,56,60,63,64,63,62,61,60,58,57,56,54,53,53,54,54,54,55# # ,56,57,59,60,62,63,63,64,65,65,65,64,63,62,61,60,60,59,58,58,57,57,56,56,56,57,60,62,64,64,63,61,59# # ,56,54,51,48,46,43,40,39,38,37,36,35,34,34,33,33,32,31,30,29,28,26,24,21,18,15,13,11,9,7,6,5,4,2,2# # ,1,1,
# # #'     55,54,53,52,53,51,49,47,46,45,44,45,48,52,57,61,64,65,63,63,62,60,59,58,57,55,54,54,54,55,55# # ,55,57,58,59,61,62,63,64,65,65,66,65,64,63,62,61,61,60,59,58,58,57,57,56,56,56,57,60,62,64,64,63,61# # ,58,56,53,51,48,45,42,40,38,37,36,35,34,33,33,32,31,31,30,28,27,26,24,22,19,16,13,11,9,7,5,4,4,3,2# # ,1,1,
# # #'     54,55,55,54,53,52,51,49,48,47,46,45,45,48,53,57,62,65,65,64,63,62,61,60,59,58,56,55,55,55,55# # ,55,56,57,58,60,61,63,64,64,65,66,66,66,65,64,62,61,60,60,59,59,58,57,57,56,55,56,57,59,61,63,64,63# # ,61,58,56,53,50,47,45,42,39,38,37,35,34,34,33,32,31,30,29,28,27,25,24,22,20,17,14,11,9,7,5,4,3,2,2# # ,1,1,
# # #'     53,55,55,55,54,53,52,51,50,48,47,46,45,45,49,53,58,63,66,67,65,64,63,62,61,60,59,57,56,56,56# # ,56,56,56,58,59,60,62,63,64,65,66,66,67,66,65,64,62,61,60,60,59,59,58,57,57,56,55,55,57,59,61,63,64# # ,63,60,58,55,52,49,47,44,41,38,37,36,34,33,32,31,31,30,29,28,26,25,23,22,20,18,15,12,9,8,6,4,3,3,2# # ,1,1,
# # #'     53,55,56,56,55,55,54,52,51,50,49,48,46,45,46,49,54,59,64,67,68,67,65,64,63,62,61,59,58,57,57# # ,57,57,57,57,58,59,61,62,63,64,65,66,67,67,66,65,64,62,61,60,60,59,59,58,57,57,56,55,55,56,59,61,63# # ,64,63,60,57,54,51,49,46,43,40,37,36,35,34,32,31,30,29,28,27,26,24,23,21,20,18,15,12,10,8,7,5,3,3,2# # ,1,1,
# # #'     54,56,57,57,57,56,55,54,53,51,50,49,48,47,45,46,49,55,60,65,69,69,68,66,65,64,62,61,60,59,58# # ,57,57,57,57,57,58,60,61,63,64,65,66,66,67,67,66,65,64,62,61,60,60,59,59,58,57,56,55,54,54,56,58,61# # ,63,64,62,59,56,53,50,48,45,42,39,37,35,34,33,31,30,29,28,27,25,24,22,21,19,17,16,13,10,8,6,5,4,3,2# # ,1,1,
# # #'     54,56,58,58,58,57,56,55,54,53,52,50,49,48,47,45,46,50,55,61,66,70,70,69,67,66,64,63,62,61,60# # ,58,58,58,58,57,58,59,60,61,63,64,65,66,67,67,67,67,65,64,62,61,60,60,59,59,58,57,56,55,54,54,55,58# # ,60,63,63,62,59,56,53,50,47,44,41,38,36,34,33,31,30,29,28,26,25,24,22,21,19,17,15,13,11,8,6,5,4,3,2# # ,1,2,
# # #'     55,57,58,58,59,58,58,57,56,54,53,52,51,49,48,47,45,46,50,56,61,67,71,71,70,68,67,65,64,63,62# # ,60,59,59,58,58,58,58,59,60,62,63,64,65,66,67,68,68,67,65,64,62,61,60,60,59,59,58,57,56,55,54,53,55# # ,58,60,62,63,61,58,55,52,49,46,43,40,37,35,33,32,30,29,28,26,25,23,22,21,19,17,14,13,11,9,6,4,3,3,2# # ,1,2,
# # #'     55,55,57,58,58,58,58,58,57,56,55,53,52,51,50,49,48,46,47,51,57,62,68,72,72,70,69,67,66,64,63# # ,62,61,60,59,59,58,58,58,59,61,62,63,65,65,66,67,68,68,67,65,64,62,61,60,60,59,58,58,57,56,55,53,53# # ,55,57,59,62,62,61,58,54,51,48,45,42,39,36,34,32,31,29,28,26,25,23,22,20,19,17,15,12,11,10,8,5,4,3# # ,2,1,2,
# # #'     57,58,56,57,58,58,58,58,58,57,56,55,54,53,52,50,49,48,47,48,52,57,63,69,73,73,71,70,68,66,65# # ,64,63,61,60,59,59,59,58,59,60,61,62,63,65,66,66,67,68,68,67,65,64,62,61,60,59,59,58,58,57,56,54,53# # ,53,54,57,59,61,62,60,57,54,50,47,44,41,38,35,33,31,29,28,26,25,23,21,20,18,17,15,12,10,9,8,6,4,3,2# # ,1,2,
# # #'     58,58,58,57,57,58,58,58,58,58,57,56,55,54,53,52,51,50,49,48,49,52,58,64,70,73,74,72,70,68,67# # ,65,64,63,61,60,60,59,59,59,59,60,61,62,64,65,66,66,67,68,68,67,65,64,62,61,60,59,59,58,57,56,55,54# # ,53,53,54,56,58,61,61,59,56,53,50,46,43,40,37,34,32,30,28,26,25,23,21,19,18,16,15,13,10,9,8,7,5,3,2# # ,1,2,
# # #'     59,58,58,58,57,58,58,58,58,58,58,57,56,55,54,53,53,51,51,50,49,49,53,59,65,70,74,74,72,71,69# # ,67,66,65,63,62,61,60,59,59,59,59,60,61,62,64,65,66,66,67,68,68,67,65,64,62,61,60,59,58,58,57,56,55# # ,54,53,52,54,56,58,60,61,59,55,52,49,45,42,40,36,33,31,28,27,25,23,22,20,18,16,14,13,11,8,7,6,5,4,2# # ,1,2)
# # #'
# # #' # Vector of age-specific fertility rates
# # #' asfr <- c(0.000415,0.00209,0.004145,0.010155,0.017665,0.027095,0.038225,0.046765,0.0582,0.07097# # ,0.083335,0.09792,0.10819,0.11661,0.117465,0.11389,0.10584,0.095805,0.081925,0.07266,0.06205,0# # .05031,0.0402,0.029295,0.023435,0.015425,0.010325,0.006225,0.00378,0.001845,0.00083,0.00046,0.00005# # ,0.000085,0.00003,
# # #'           0.00052,0.001915,0.005605,0.009435,0.01871,0.02803,0.03896,0.04524,0.057105,0.070205,0# # .084105,0.1004,0.10972,0.12058,0.121825,0.11956,0.109495,0.099345,0.090625,0.075065,0.064575,0# # .05104,0.0413,0.03231,0.02354,0.01639,0.009985,0.00634,0.004215,0.001875,0.00091,0.00048,0.00014,0# # .00012,0.000065,
# # #'           0.000685,0.00211,0.00459,0.009075,0.0181,0.026515,0.036495,0.04599,0.058185,0.070745,0# # .082965,0.097255,0.10583,0.116975,0.12034,0.121645,0.118705,0.105155,0.0935,0.078975,0.069225,0# # .055105,0.04294,0.032315,0.024895,0.01653,0.012175,0.007115,0.003845,0.002,0.00081,0.000385,0# # .000135,0.0001,0.00007,
# # #'           0.000395,0.002155,0.00538,0.01025,0.01744,0.02757,0.03798,0.047435,0.059845,0.070295,0# # .085905,0.097875,0.113365,0.12143,0.12913,0.13287,0.126885,0.11332,0.098785,0.08711,0.070315,0# # .05895,0.044535,0.034625,0.026315,0.018275,0.012505,0.007335,0.00418,0.002295,0.000985,0.000415,0# # .000175,0.000105,0.000035,
# # #'           0.00056,0.001925,0.00536,0.00899,0.01594,0.02764,0.0387,0.048325,0.05559,0.069995,0# # .085535,0.09787,0.11428,0.126135,0.135655,0.13816,0.132265,0.12517,0.106395,0.09231,0.07695,0.06148# # ,0.05132,0.037605,0.0289,0.019855,0.013335,0.007535,0.00457,0.002155,0.00108,0.00065,0.00012,0# # .000105,0.000035,
# # #'           0.000515,0.00204,0.00449,0.008325,0.01641,0.027835,0.03772,0.046995,0.054845,0.071795# # ,0.08601,0.09841,0.11213,0.129055,0.137675,0.138955,0.136445,0.128615,0.11401,0.09782,0.0793,0# # .06689,0.051755,0.04049,0.030265,0.02152,0.014165,0.00863,0.00531,0.00286,0.0009,0.000485,0.00024,0# # .00005,0.000035,
# # #'           0.00061,0.001715,0.004275,0.00819,0.017095,0.02619,0.03677,0.047475,0.05763,0.069865,0# # .081945,0.09929,0.110015,0.13017,0.13437,0.14298,0.13867,0.13124,0.114545,0.10012,0.0854,0.07069,0# # .05289,0.04139,0.0313,0.021265,0.01365,0.009055,0.005025,0.0026,0.001515,0.000605,0.00019,0.00014,0# # .00005,
# # #'           0.00043,0.001745,0.00483,0.00803,0.017205,0.026975,0.03812,0.0498,0.05848,0.0711,0# # .085385,0.099465,0.116595,0.132605,0.141035,0.145675,0.14637,0.13643,0.1226,0.109555,0.09091,0# # .07415,0.05954,0.044,0.03277,0.023015,0.015135,0.009085,0.00577,0.00288,0.000945,0.000925,0.000365# # ,0.00016,0.000035,
# # #'           0.00058,0.00181,0.00414,0.007795,0.0171,0.02706,0.040175,0.0497,0.06138,0.0754,0.0849# # ,0.101365,0.113765,0.12703,0.14095,0.145175,0.1454,0.13895,0.125435,0.109375,0.0931,0.07791,0# # .060535,0.046815,0.03495,0.02434,0.01647,0.010475,0.006015,0.003015,0.00146,0.000735,0.000505,0# # .000145,0.000085,
# # #'           0.0005,0.00131,0.00409,0.007815,0.016955,0.02869,0.041145,0.05194,0.062625,0.07733,0# # .089215,0.09915,0.114505,0.13087,0.14321,0.1474,0.14718,0.13722,0.125395,0.110985,0.09451,0.078285# # ,0.060645,0.049175,0.036805,0.024725,0.01707,0.01021,0.00565,0.002975,0.001535,0.000875,0.000295,0# # .00017,0.00007,
# # #'           0.00059,0.00142,0.004095,0.007065,0.01605,0.028775,0.038975,0.05168,0.062965,0.07423,0# # .08839,0.102815,0.11722,0.128075,0.140695,0.14827,0.147145,0.139575,0.124925,0.115005,0.10046,0# # .07994,0.065455,0.05039,0.036865,0.02644,0.018245,0.01033,0.006675,0.003285,0.0018,0.00082,0.0003,0# # .000275,0.000155,
# # #'           0.000415,0.001565,0.00368,0.007465,0.015375,0.027185,0.039185,0.05004,0.06393,0.078245# # ,0.091495,0.10549,0.119415,0.132825,0.14508,0.146535,0.152615,0.14506,0.129695,0.116805,0.100135,0# # .08581,0.06692,0.0517,0.04117,0.027675,0.01863,0.01183,0.006305,0.00375,0.00199,0.00091,0.000435,0# # .000115,0.000185,
# # #'           0.00039,0.00167,0.003365,0.00721,0.015025,0.02415,0.03536,0.0473,0.05979,0.07669,0# # .08609,0.099455,0.11409,0.127615,0.135055,0.139255,0.142215,0.13442,0.12758,0.11536,0.095805,0# # .084415,0.06851,0.050215,0.03904,0.028855,0.01871,0.011115,0.00661,0.00322,0.001785,0.000885,0# # .00032,0.00016,0.00017,
# # #'           0.00037,0.00139,0.00349,0.00648,0.013235,0.022885,0.03429,0.04627,0.06062,0.0747,0# # .08875,0.102265,0.113975,0.126025,0.133335,0.14266,0.145635,0.135565,0.125785,0.11608,0.099185,0# # .082475,0.064515,0.053475,0.03974,0.028015,0.01857,0.012445,0.006835,0.003715,0.00195,0.001035,0# # .000495,0.000385,0.000245,
# # #'           0.00055,0.00141,0.003325,0.0063,0.013195,0.02156,0.03351,0.044095,0.057585,0.07177,0# # .08555,0.10087,0.11176,0.12691,0.133945,0.14199,0.14091,0.140015,0.126205,0.11514,0.096115,0.082895# # ,0.06829,0.05249,0.04038,0.0289,0.018745,0.0116,0.006765,0.00338,0.00179,0.000925,0.00052,0.000375# # ,0.00023,
# # #'           0.00046,0.001105,0.00294,0.006765,0.01239,0.019805,0.029245,0.04243,0.056205,0.071675# # ,0.086795,0.104835,0.113775,0.126065,0.136305,0.140305,0.139335,0.134685,0.12758,0.11418,0.0979,0# # .080865,0.066865,0.052935,0.04007,0.030485,0.01916,0.01159,0.0076,0.003765,0.00198,0.00097,0.0007,0# # .000265,0.000115,
# # #'           0.000295,0.00114,0.003045,0.0056,0.0115,0.02006,0.028345,0.042025,0.053665,0.0689,0# # .088195,0.102155,0.11291,0.126765,0.13238,0.139095,0.137405,0.13127,0.119895,0.11279,0.097485,0# # .08156,0.06475,0.05382,0.03895,0.029045,0.018885,0.01236,0.006625,0.003655,0.002055,0.00118,0.00053# # ,0.000275,0.000295,
# # #'           0.0005,0.001235,0.002775,0.005245,0.01218,0.019915,0.029575,0.038195,0.052965,0.06899# # ,0.084725,0.101895,0.11375,0.126235,0.135615,0.13995,0.13603,0.130845,0.119245,0.11024,0.09851,0# # .083725,0.067125,0.053155,0.041975,0.03034,0.020565,0.0128,0.0077,0.00427,0.00218,0.00107,0.000655# # ,0.000375,0.000175,
# # #'           0.00033,0.00123,0.002695,0.00597,0.01165,0.01963,0.03009,0.03768,0.048195,0.063535,0# # .078305,0.09598,0.107535,0.119215,0.129095,0.131615,0.133445,0.128725,0.120115,0.10175,0.09485,0# # .081035,0.06597,0.05288,0.040885,0.030075,0.020595,0.01365,0.0073,0.00487,0.00216,0.001375,0.0006,0# # .000285,0.000465,
# # #'           0.00026,0.00117,0.00229,0.00592,0.011875,0.01965,0.027745,0.039155,0.04793,0.061335,0# # .0765,0.0926,0.10439,0.120235,0.12707,0.13096,0.13116,0.12526,0.116655,0.10556,0.092845,0.07854,0# # .063975,0.05414,0.04103,0.02982,0.0198,0.01193,0.00737,0.003905,0.002225,0.00128,0.000515,0.000455# # ,0.0002)
# # #'
# # #' # Vector of survival rates for males
# # #' sr_m <- c(0.9966,0.9993,0.9998,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0.9999,0.9999,0.9998,0# # .9998,0.9998,0.9998,0.9998,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9994,0.9994,0.9993,0# # .9993,0.9994,0.9993,0.9992,0.9993,0.9993,0.9993,0.9993,0.9992,0.9991,0.999,0.9989,0.9989,0.9987,0# # .9986,0.9985,0.9983,0.9981,0.9982,0.998,0.9979,0.9978,0.9973,0.9969,0.9967,0.9965,0.9963,0.9957,0# # .9951,0.9945,0.9941,0.9938,0.9931,0.9922,0.9913,0.9908,0.99,0.9882,0.9866,0.9856,0.9844,0.9823,0# # .9796,0.9775,0.9755,0.9718,0.9685,0.9664,0.9631,0.958,0.9541,0.9495,0.9423,0.9358,0.929,0.9193,0# # .9094,0.9001,0.8908,0.8804,0.8633,0.849,0.8363,0.8167,0.7994,0.7831,0.7606,0.74,0.7174,0.6948,0# # .6811,0.6598,0.6388,0.6174,0.7246,
# # #'           0.9965,0.9993,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9995,0.9993,0.9992,0.9992,0.9992,0.9992,0.9993,0.9993,0# # .9991,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0.9992,0.9992,0.9991,0.9991,0.9991,0.9989,0.9989,0# # .9989,0.9987,0.9987,0.9986,0.9981,0.9979,0.9979,0.9977,0.9971,0.9968,0.997,0.9966,0.996,0.9959,0# # .9954,0.995,0.9946,0.9941,0.9934,0.9925,0.9918,0.9907,0.9896,0.9891,0.9875,0.9857,0.9845,0.983,0# # .9812,0.9785,0.9757,0.9736,0.9701,0.9668,0.9641,0.9599,0.9556,0.95,0.9447,0.9384,0.9315,0.925,0# # .9143,0.9031,0.8924,0.8799,0.8653,0.8488,0.8359,0.8257,0.8106,0.7911,0.7647,0.7396,0.7218,0.6989,0# # .6796,0.6577,0.6363,0.6142,0.5535,
# # #'           0.9966,0.9993,0.9998,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9995,0.9992,0.9991,0.9991,0.9992,0.9993,0.9993,0# # .9993,0.9993,0.9993,0.9994,0.9994,0.9993,0.9993,0.9992,0.9991,0.9992,0.9991,0.999,0.9989,0.9987,0# # .9986,0.9986,0.9985,0.9984,0.9982,0.9981,0.9978,0.9973,0.9971,0.9971,0.9969,0.9967,0.9965,0.9958,0# # .9953,0.9951,0.9945,0.9937,0.9929,0.9926,0.9923,0.9906,0.99,0.9892,0.9874,0.9864,0.9848,0.983,0.981# # ,0.979,0.9775,0.9747,0.9715,0.969,0.9653,0.9612,0.9565,0.9513,0.9466,0.9398,0.932,0.924,0.9177,0# # .9076,0.8949,0.8828,0.8699,0.8589,0.8413,0.8234,0.8063,0.782,0.7602,0.7399,0.7241,0.7089,0.679,0# # .6563,0.6344,0.6134,0.5604,
# # #'           0.9969,0.9993,0.9996,0.9997,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9994,0.9993,0.9993,0.9992,0.999,0.9992,0.9993,0# # .9993,0.9993,0.9994,0.9995,0.9994,0.9992,0.9992,0.9993,0.9993,0.9993,0.9992,0.9991,0.9991,0.9989,0# # .9987,0.9987,0.9985,0.9984,0.9983,0.9981,0.998,0.9978,0.9976,0.9976,0.9971,0.9966,0.9962,0.996,0# # .9956,0.995,0.9947,0.9943,0.9931,0.9923,0.9916,0.991,0.9906,0.9893,0.9879,0.987,0.9851,0.9833,0# # .9817,0.9789,0.9767,0.9754,0.9719,0.9679,0.9651,0.9612,0.9577,0.9521,0.9454,0.94,0.9328,0.9256,0# # .9161,0.9066,0.8969,0.8831,0.87,0.8527,0.8364,0.8206,0.8016,0.7879,0.7665,0.7305,0.7086,0.7018,0# # .6734,0.6506,0.628,0.6056,0.587,
# # #'           0.9969,0.9993,0.9997,0.9997,0.9998,0.9999,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9994,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0# # .9994,0.9995,0.9994,0.9994,0.9994,0.9995,0.9995,0.9994,0.9992,0.9991,0.9992,0.9992,0.999,0.9989,0# # .9988,0.9987,0.9986,0.9985,0.9981,0.9981,0.998,0.9976,0.9974,0.9972,0.9969,0.9968,0.9966,0.9962,0# # .9955,0.995,0.9945,0.994,0.9938,0.9933,0.9924,0.9914,0.9902,0.9893,0.9885,0.9866,0.9846,0.9837,0# # .9819,0.9799,0.9778,0.9739,0.9718,0.9695,0.9655,0.9622,0.958,0.9527,0.9476,0.9424,0.9355,0.9248,0# # .9156,0.9069,0.8979,0.8869,0.8705,0.8563,0.8412,0.8249,0.8104,0.7927,0.7748,0.7577,0.7306,0.7084,0# # .6884,0.6664,0.6454,0.6234,0.5009,
# # #'           0.9972,0.9994,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9995,0.9994,0.9992,0.9991,0.9992,0.9993,0.9992,0.9992,0# # .9993,0.9994,0.9993,0.9993,0.9994,0.9994,0.9993,0.9994,0.9993,0.9992,0.9993,0.9991,0.9991,0.9991,0# # .9989,0.9989,0.9989,0.9986,0.9983,0.9981,0.998,0.9979,0.9977,0.9972,0.9966,0.9965,0.9965,0.9963,0# # .9957,0.9953,0.9947,0.994,0.9936,0.9932,0.9925,0.9917,0.991,0.9903,0.9886,0.9869,0.9858,0.9843,0# # .9825,0.9805,0.9785,0.9756,0.9725,0.9705,0.9681,0.9653,0.9608,0.9554,0.9514,0.946,0.9386,0.9299,0# # .9223,0.9144,0.9018,0.8894,0.8776,0.8645,0.8453,0.8273,0.8171,0.8011,0.7761,0.749,0.7403,0.7271,0# # .6924,0.6703,0.6479,0.6255,0.5403,
# # #'           0.9979,0.9994,0.9997,0.9998,0.9998,0.9999,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9993,0.9994,0.9993,0# # .9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9993,0.9994,0.9994,0.9992,0.9992,0.9993,0.9993,0.999,0# # .9989,0.9989,0.9986,0.9985,0.9984,0.9983,0.9981,0.9979,0.9978,0.9974,0.9972,0.9972,0.9967,0.9958,0# # .9954,0.9953,0.9946,0.9943,0.9941,0.9933,0.9922,0.9917,0.9908,0.9897,0.989,0.9875,0.9851,0.9841,0# # .983,0.981,0.9792,0.9772,0.9748,0.9708,0.967,0.9638,0.96,0.9559,0.9513,0.9442,0.9363,0.9294,0.9214# # ,0.9121,0.9011,0.8887,0.8762,0.8614,0.8452,0.8306,0.8111,0.7966,0.7811,0.7447,0.7124,0.6993,0.6873# # ,0.665,0.6426,0.6206,0.6098,
# # #'           0.9974,0.9994,0.9998,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9996,0.9995,0.9994,0.9994,0.9993,0.9992,0.9993,0.9994,0# # .9994,0.9994,0.9995,0.9994,0.9993,0.9995,0.9995,0.9993,0.9993,0.9994,0.9992,0.9991,0.9991,0.999,0# # .999,0.9989,0.9986,0.9986,0.9986,0.9984,0.9982,0.9979,0.9979,0.9978,0.9974,0.9969,0.9965,0.9959,0# # .9954,0.9953,0.9949,0.9943,0.994,0.9935,0.9926,0.9918,0.991,0.9902,0.9891,0.9872,0.9852,0.985,0# # .9844,0.9824,0.9797,0.9771,0.975,0.9725,0.9691,0.9658,0.9617,0.9568,0.9522,0.9466,0.9394,0.9306,0# # .9237,0.916,0.9036,0.8915,0.8787,0.8654,0.8498,0.8306,0.8147,0.7989,0.7774,0.7561,0.7387,0.7168,0# # .6941,0.672,0.6496,0.6273,0.5327,
# # #'           0.9977,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9996,0.9993,0.9992,0.9993,0.9993,0.9994,0.9993,0.9992,0# # .9992,0.9992,0.9993,0.9993,0.9993,0.9994,0.9994,0.9994,0.9993,0.9993,0.9993,0.9992,0.9992,0.9991,0# # .9989,0.9989,0.9988,0.9986,0.9985,0.9983,0.998,0.998,0.9979,0.9976,0.9971,0.9967,0.9963,0.9962,0# # .9961,0.9957,0.9952,0.9947,0.994,0.9933,0.993,0.9922,0.991,0.99,0.9888,0.9874,0.9866,0.9854,0.9839# # ,0.9827,0.9807,0.9788,0.9765,0.9734,0.9711,0.9675,0.9634,0.9591,0.9524,0.9475,0.9414,0.9329,0.9248# # ,0.916,0.9056,0.8949,0.8821,0.8679,0.8541,0.8379,0.8184,0.7978,0.7775,0.7522,0.7237,0.7016,0.6906,0# # .6677,0.6448,0.6226,0.5853,
# # #'           0.9979,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9993,0.9992,0.9993,0# # .9993,0.9993,0.9992,0.9993,0.9992,0.9992,0.9992,0.9993,0.9993,0.9993,0.9992,0.9992,0.9992,0.9992,0# # .9991,0.999,0.9988,0.9986,0.9985,0.9984,0.9982,0.9982,0.9981,0.9977,0.9973,0.9968,0.9967,0.9963,0# # .9957,0.9958,0.9955,0.9947,0.9939,0.9935,0.993,0.9923,0.9914,0.9903,0.9891,0.9879,0.9872,0.9862,0# # .9843,0.982,0.9807,0.9791,0.9766,0.9743,0.9704,0.9665,0.9646,0.9606,0.954,0.9489,0.9427,0.9326,0# # .9246,0.9172,0.9075,0.8967,0.8833,0.8673,0.8531,0.8359,0.817,0.8054,0.784,0.7543,0.7308,0.7135,0# # .6957,0.6731,0.6503,0.6278,0.5519,
# # #'           0.9978,0.9994,0.9997,0.9997,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9998,0.9997,0.9997,0.9996,0.9994,0.9994,0.9994,0.9994,0.9992,0.9993,0# # .9994,0.9993,0.9994,0.9993,0.9992,0.9993,0.9993,0.9993,0.9993,0.9992,0.9991,0.9992,0.9991,0.9991,0# # .9992,0.9991,0.999,0.9986,0.9984,0.9984,0.9983,0.9981,0.998,0.9977,0.9972,0.997,0.9968,0.9964,0.996# # ,0.9958,0.9955,0.9946,0.994,0.9936,0.9934,0.9926,0.9914,0.9908,0.9901,0.9885,0.9874,0.9868,0.9857,0# # .9835,0.9818,0.9801,0.9777,0.9748,0.9712,0.968,0.9642,0.9599,0.9554,0.9506,0.9432,0.935,0.9293,0# # .9207,0.9097,0.8971,0.8852,0.8716,0.854,0.8404,0.8243,0.803,0.7838,0.7586,0.728,0.7077,0.693,0.6698# # ,0.6468,0.6233,0.5746,
# # #'           0.9977,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9995,0.9995,0.9994,0.9993,0.9993,0.9993,0.9992,0# # .9994,0.9994,0.9993,0.9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9994,0.9993,0.9994,0.9994,0.9992,0# # .999,0.9989,0.9989,0.9987,0.9988,0.9988,0.9984,0.9981,0.9978,0.9976,0.9974,0.9972,0.997,0.9966,0# # .9961,0.9957,0.9953,0.9949,0.9946,0.9938,0.993,0.9925,0.9918,0.9909,0.9895,0.9883,0.9876,0.9864,0# # .9857,0.9839,0.9812,0.9796,0.9779,0.9757,0.973,0.9686,0.9652,0.961,0.954,0.949,0.9435,0.9366,0.9294# # ,0.9196,0.9108,0.9006,0.887,0.8732,0.8575,0.8421,0.8245,0.8028,0.7852,0.7671,0.741,0.7179,0.6987,0# # .6757,0.6526,0.6298,0.55,
# # #'           0.9981,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9996,0.9995,0.9995,0.9994,0.9993,0.9993,0.9993,0.9993,0# # .9994,0.9993,0.9993,0.9993,0.9994,0.9992,0.9993,0.9994,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0# # .9991,0.9991,0.9991,0.9989,0.9986,0.9985,0.9985,0.9982,0.9979,0.9976,0.9974,0.9972,0.9972,0.9969,0# # .9964,0.9959,0.9952,0.9952,0.9947,0.9934,0.9931,0.9928,0.9922,0.9915,0.9904,0.989,0.9876,0.9867,0# # .9852,0.9834,0.9819,0.9804,0.9788,0.9763,0.9734,0.9707,0.9659,0.9608,0.9562,0.9509,0.9461,0.9416,0# # .9336,0.9209,0.9098,0.9,0.8881,0.8748,0.8621,0.8474,0.8282,0.8065,0.7817,0.763,0.7445,0.7198,0.6988# # ,0.6753,0.6519,0.6284,0.5699,
# # #'           0.9975,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9997,0.9996,0.9995,0.9993,0.9993,0.9993,0.9993,0# # .9992,0.9992,0.9993,0.9993,0.9994,0.9994,0.9994,0.9993,0.9993,0.9993,0.9994,0.9994,0.9992,0.9991,0# # .999,0.999,0.9991,0.999,0.9988,0.9986,0.9985,0.9983,0.9981,0.9978,0.9977,0.9976,0.9972,0.9967,0# # .9962,0.9958,0.9954,0.9952,0.995,0.9944,0.9936,0.9927,0.992,0.9915,0.9907,0.9897,0.9881,0.987,0# # .9865,0.9849,0.9826,0.9814,0.9796,0.976,0.9724,0.9698,0.9668,0.9622,0.9571,0.9525,0.9464,0.9377,0# # .93,0.9225,0.9122,0.9007,0.8877,0.8723,0.8573,0.8414,0.8204,0.8008,0.7855,0.7631,0.7423,0.7212,0# # .6924,0.6687,0.6449,0.6221,0.5931,
# # #'           0.9976,0.9995,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9998,0.9998,0.9999,0.9999,0.9998,0.9997,0.9995,0.9994,0.9994,0.9994,0.9994,0.9993,0.9993,0# # .9993,0.9992,0.9992,0.9992,0.9992,0.9992,0.9992,0.9993,0.9994,0.9994,0.9992,0.999,0.9991,0.9992,0# # .9992,0.999,0.999,0.999,0.9988,0.9986,0.9984,0.9983,0.9983,0.998,0.9975,0.9974,0.9974,0.9967,0.9962# # ,0.9961,0.996,0.9956,0.995,0.9945,0.9937,0.9925,0.9919,0.9913,0.9904,0.9897,0.9885,0.9873,0.9861,0# # .9846,0.9831,0.9812,0.9794,0.9775,0.9742,0.9706,0.9669,0.9635,0.9607,0.9554,0.9482,0.9416,0.9347,0# # .9267,0.9148,0.9034,0.894,0.8806,0.8662,0.8452,0.8279,0.8102,0.7831,0.7623,0.7356,0.7147,0.6972,0# # .6729,0.649,0.6247,0.5506,
# # #'           0.9978,0.9995,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9994,0.9993,0.9994,0.9993,0.9993,0.9993,0# # .9993,0.9994,0.9993,0.9993,0.9992,0.9992,0.9992,0.9991,0.9991,0.9992,0.9993,0.9992,0.9993,0.9993,0# # .9992,0.9991,0.9989,0.9988,0.9987,0.9987,0.9986,0.9984,0.998,0.9978,0.9976,0.9972,0.9973,0.9972,0# # .9969,0.9965,0.996,0.9954,0.995,0.9946,0.9939,0.9929,0.9921,0.9914,0.9909,0.9904,0.9891,0.9874,0# # .9861,0.9848,0.9831,0.9815,0.9801,0.9787,0.9751,0.9712,0.9683,0.9641,0.9599,0.9562,0.9503,0.9433,0# # .9355,0.9263,0.9181,0.9065,0.8934,0.8813,0.8702,0.8525,0.8296,0.8156,0.7995,0.7766,0.7577,0.7371,0# # .7097,0.6864,0.6629,0.6394,0.5187,
# # #'           0.9976,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9995,0.9994,0.9994,0.9994,0.9994,0.9993,0.9991,0# # .9991,0.9992,0.9992,0.9993,0.9993,0.9994,0.9994,0.9992,0.9992,0.9992,0.9991,0.9991,0.9992,0.9993,0# # .9991,0.999,0.9989,0.9989,0.9989,0.9988,0.9988,0.9985,0.9982,0.9981,0.9978,0.9977,0.9973,0.9967,0# # .9964,0.9961,0.9958,0.9954,0.9948,0.9944,0.9939,0.9934,0.9928,0.9917,0.9908,0.9898,0.9885,0.9875,0# # .9868,0.9856,0.984,0.9813,0.9792,0.9781,0.9749,0.9713,0.9693,0.9664,0.9605,0.9552,0.949,0.9427,0# # .9372,0.9288,0.9191,0.9054,0.8918,0.8799,0.8657,0.8477,0.8314,0.814,0.7884,0.767,0.7501,0.7284,0# # .7013,0.6772,0.6533,0.6287,0.6158,
# # #'           0.9978,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9996,0.9996,0.9995,0.9995,0.9994,0.9995,0.9993,0# # .9992,0.9993,0.9993,0.9994,0.9993,0.9992,0.9991,0.9992,0.9992,0.9992,0.9992,0.9992,0.9992,0.999,0# # .9991,0.9991,0.9988,0.9988,0.9988,0.9988,0.9986,0.9984,0.9983,0.9979,0.9978,0.9977,0.9976,0.9974,0# # .9967,0.9962,0.9959,0.9958,0.9955,0.9949,0.9941,0.993,0.992,0.9918,0.991,0.99,0.9888,0.9874,0.9866# # ,0.9855,0.9839,0.9821,0.9802,0.9775,0.9757,0.9738,0.9693,0.9656,0.9612,0.9563,0.9508,0.9438,0.9375# # ,0.9309,0.9202,0.9081,0.8966,0.8827,0.8714,0.8598,0.8396,0.8147,0.7931,0.772,0.7499,0.7294,0.7059,0# # .6818,0.6574,0.6333,0.554,
# # #'           0.9979,0.9996,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9999,0.9998,0.9996,0.9995,0.9995,0.9995,0.9994,0.9993,0.9993,0.9992,0# # .9993,0.9993,0.9991,0.9992,0.9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9991,0.9991,0.9992,0.9991,0# # .9989,0.9989,0.999,0.9989,0.9988,0.9987,0.9986,0.9986,0.9985,0.9981,0.998,0.9979,0.9974,0.9972,0# # .997,0.9965,0.9961,0.9956,0.9955,0.9953,0.9946,0.994,0.9932,0.9917,0.9903,0.9901,0.9895,0.9883,0# # .9877,0.9857,0.9834,0.9828,0.9815,0.979,0.9768,0.9747,0.9716,0.9667,0.9611,0.9571,0.9539,0.9471,0# # .9387,0.9296,0.9189,0.9088,0.8982,0.8842,0.8669,0.847,0.8249,0.8068,0.7907,0.7732,0.7507,0.7199,0# # .6941,0.6689,0.6435,0.6187,0.6097,
# # #'           0.9981,0.9996,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9999,0.9997,0.9996,0.9996,0.9996,0.9994,0.9993,0.9994,0.9993,0.9993,0# # .9994,0.9993,0.9992,0.9993,0.9993,0.9994,0.9994,0.9993,0.9992,0.9991,0.9992,0.9992,0.9992,0.9992,0# # .999,0.999,0.999,0.999,0.9988,0.9988,0.9987,0.9985,0.9985,0.9983,0.9979,0.9978,0.9975,0.997,0.9969# # ,0.9968,0.9964,0.996,0.9956,0.9949,0.9941,0.9935,0.9928,0.9921,0.9912,0.99,0.9888,0.9877,0.9867,0# # .9856,0.9839,0.9826,0.9807,0.9793,0.9773,0.9739,0.9704,0.9663,0.9632,0.9589,0.953,0.9456,0.9376,0# # .9295,0.9208,0.9115,0.8987,0.8831,0.8685,0.8532,0.8322,0.8139,0.7997,0.7768,0.7487,0.7253,0.7054,0# # .681,0.6567,0.6329,0.5357)
# # #'
# # #' # Vector of survival rates for females
# # #' sr_f <- c(0.9966,0.9993,0.9998,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0.9999,0.9999,0.9998,0# # .9998,0.9998,0.9998,0.9998,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9994,0.9994,0.9993,0# # .9993,0.9994,0.9993,0.9992,0.9993,0.9993,0.9993,0.9993,0.9992,0.9991,0.999,0.9989,0.9989,0.9987,0# # .9986,0.9985,0.9983,0.9981,0.9982,0.998,0.9979,0.9978,0.9973,0.9969,0.9967,0.9965,0.9963,0.9957,0# # .9951,0.9945,0.9941,0.9938,0.9931,0.9922,0.9913,0.9908,0.99,0.9882,0.9866,0.9856,0.9844,0.9823,0# # .9796,0.9775,0.9755,0.9718,0.9685,0.9664,0.9631,0.958,0.9541,0.9495,0.9423,0.9358,0.929,0.9193,0# # .9094,0.9001,0.8908,0.8804,0.8633,0.849,0.8363,0.8167,0.7994,0.7831,0.7606,0.74,0.7174,0.6948,0# # .6811,0.6598,0.6388,0.6174,0.5734,
# # #'           0.9965,0.9993,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9995,0.9993,0.9992,0.9992,0.9992,0.9992,0.9993,0.9993,0# # .9991,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0.9992,0.9992,0.9991,0.9991,0.9991,0.9989,0.9989,0# # .9989,0.9987,0.9987,0.9986,0.9981,0.9979,0.9979,0.9977,0.9971,0.9968,0.997,0.9966,0.996,0.9959,0# # .9954,0.995,0.9946,0.9941,0.9934,0.9925,0.9918,0.9907,0.9896,0.9891,0.9875,0.9857,0.9845,0.983,0# # .9812,0.9785,0.9757,0.9736,0.9701,0.9668,0.9641,0.9599,0.9556,0.95,0.9447,0.9384,0.9315,0.925,0# # .9143,0.9031,0.8924,0.8799,0.8653,0.8488,0.8359,0.8257,0.8106,0.7911,0.7647,0.7396,0.7218,0.6989,0# # .6796,0.6577,0.6363,0.6142,0.57,
# # #'           0.9966,0.9993,0.9998,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9995,0.9992,0.9991,0.9991,0.9992,0.9993,0.9993,0# # .9993,0.9993,0.9993,0.9994,0.9994,0.9993,0.9993,0.9992,0.9991,0.9992,0.9991,0.999,0.9989,0.9987,0# # .9986,0.9986,0.9985,0.9984,0.9982,0.9981,0.9978,0.9973,0.9971,0.9971,0.9969,0.9967,0.9965,0.9958,0# # .9953,0.9951,0.9945,0.9937,0.9929,0.9926,0.9923,0.9906,0.99,0.9892,0.9874,0.9864,0.9848,0.983,0.981# # ,0.979,0.9775,0.9747,0.9715,0.969,0.9653,0.9612,0.9565,0.9513,0.9466,0.9398,0.932,0.924,0.9177,0# # .9076,0.8949,0.8828,0.8699,0.8589,0.8413,0.8234,0.8063,0.782,0.7602,0.7399,0.7241,0.7089,0.679,0# # .6563,0.6344,0.6134,0.5669,
# # #'           0.9969,0.9993,0.9996,0.9997,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9994,0.9993,0.9993,0.9992,0.999,0.9992,0.9993,0# # .9993,0.9993,0.9994,0.9995,0.9994,0.9992,0.9992,0.9993,0.9993,0.9993,0.9992,0.9991,0.9991,0.9989,0# # .9987,0.9987,0.9985,0.9984,0.9983,0.9981,0.998,0.9978,0.9976,0.9976,0.9971,0.9966,0.9962,0.996,0# # .9956,0.995,0.9947,0.9943,0.9931,0.9923,0.9916,0.991,0.9906,0.9893,0.9879,0.987,0.9851,0.9833,0# # .9817,0.9789,0.9767,0.9754,0.9719,0.9679,0.9651,0.9612,0.9577,0.9521,0.9454,0.94,0.9328,0.9256,0# # .9161,0.9066,0.8969,0.8831,0.87,0.8527,0.8364,0.8206,0.8016,0.7879,0.7665,0.7305,0.7086,0.7018,0# # .6734,0.6506,0.628,0.6056,0.5611,
# # #'           0.9969,0.9993,0.9997,0.9997,0.9998,0.9999,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9994,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0# # .9994,0.9995,0.9994,0.9994,0.9994,0.9995,0.9995,0.9994,0.9992,0.9991,0.9992,0.9992,0.999,0.9989,0# # .9988,0.9987,0.9986,0.9985,0.9981,0.9981,0.998,0.9976,0.9974,0.9972,0.9969,0.9968,0.9966,0.9962,0# # .9955,0.995,0.9945,0.994,0.9938,0.9933,0.9924,0.9914,0.9902,0.9893,0.9885,0.9866,0.9846,0.9837,0# # .9819,0.9799,0.9778,0.9739,0.9718,0.9695,0.9655,0.9622,0.958,0.9527,0.9476,0.9424,0.9355,0.9248,0# # .9156,0.9069,0.8979,0.8869,0.8705,0.8563,0.8412,0.8249,0.8104,0.7927,0.7748,0.7577,0.7306,0.7084,0# # .6884,0.6664,0.6454,0.6234,0.5784,
# # #'           0.9972,0.9994,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9995,0.9994,0.9992,0.9991,0.9992,0.9993,0.9992,0.9992,0# # .9993,0.9994,0.9993,0.9993,0.9994,0.9994,0.9993,0.9994,0.9993,0.9992,0.9993,0.9991,0.9991,0.9991,0# # .9989,0.9989,0.9989,0.9986,0.9983,0.9981,0.998,0.9979,0.9977,0.9972,0.9966,0.9965,0.9965,0.9963,0# # .9957,0.9953,0.9947,0.994,0.9936,0.9932,0.9925,0.9917,0.991,0.9903,0.9886,0.9869,0.9858,0.9843,0# # .9825,0.9805,0.9785,0.9756,0.9725,0.9705,0.9681,0.9653,0.9608,0.9554,0.9514,0.946,0.9386,0.9299,0# # .9223,0.9144,0.9018,0.8894,0.8776,0.8645,0.8453,0.8273,0.8171,0.8011,0.7761,0.749,0.7403,0.7271,0# # .6924,0.6703,0.6479,0.6255,0.5791,
# # #'           0.9979,0.9994,0.9997,0.9998,0.9998,0.9999,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9993,0.9994,0.9993,0# # .9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9993,0.9994,0.9994,0.9992,0.9992,0.9993,0.9993,0.999,0# # .9989,0.9989,0.9986,0.9985,0.9984,0.9983,0.9981,0.9979,0.9978,0.9974,0.9972,0.9972,0.9967,0.9958,0# # .9954,0.9953,0.9946,0.9943,0.9941,0.9933,0.9922,0.9917,0.9908,0.9897,0.989,0.9875,0.9851,0.9841,0# # .983,0.981,0.9792,0.9772,0.9748,0.9708,0.967,0.9638,0.96,0.9559,0.9513,0.9442,0.9363,0.9294,0.9214# # ,0.9121,0.9011,0.8887,0.8762,0.8614,0.8452,0.8306,0.8111,0.7966,0.7811,0.7447,0.7124,0.6993,0.6873# # ,0.665,0.6426,0.6206,0.5745,
# # #'           0.9974,0.9994,0.9998,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9998,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9996,0.9995,0.9994,0.9994,0.9993,0.9992,0.9993,0.9994,0# # .9994,0.9994,0.9995,0.9994,0.9993,0.9995,0.9995,0.9993,0.9993,0.9994,0.9992,0.9991,0.9991,0.999,0# # .999,0.9989,0.9986,0.9986,0.9986,0.9984,0.9982,0.9979,0.9979,0.9978,0.9974,0.9969,0.9965,0.9959,0# # .9954,0.9953,0.9949,0.9943,0.994,0.9935,0.9926,0.9918,0.991,0.9902,0.9891,0.9872,0.9852,0.985,0# # .9844,0.9824,0.9797,0.9771,0.975,0.9725,0.9691,0.9658,0.9617,0.9568,0.9522,0.9466,0.9394,0.9306,0# # .9237,0.916,0.9036,0.8915,0.8787,0.8654,0.8498,0.8306,0.8147,0.7989,0.7774,0.7561,0.7387,0.7168,0# # .6941,0.672,0.6496,0.6273,0.5804,
# # #'           0.9977,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9996,0.9993,0.9992,0.9993,0.9993,0.9994,0.9993,0.9992,0# # .9992,0.9992,0.9993,0.9993,0.9993,0.9994,0.9994,0.9994,0.9993,0.9993,0.9993,0.9992,0.9992,0.9991,0# # .9989,0.9989,0.9988,0.9986,0.9985,0.9983,0.998,0.998,0.9979,0.9976,0.9971,0.9967,0.9963,0.9962,0# # .9961,0.9957,0.9952,0.9947,0.994,0.9933,0.993,0.9922,0.991,0.99,0.9888,0.9874,0.9866,0.9854,0.9839# # ,0.9827,0.9807,0.9788,0.9765,0.9734,0.9711,0.9675,0.9634,0.9591,0.9524,0.9475,0.9414,0.9329,0.9248# # ,0.916,0.9056,0.8949,0.8821,0.8679,0.8541,0.8379,0.8184,0.7978,0.7775,0.7522,0.7237,0.7016,0.6906,0# # .6677,0.6448,0.6226,0.5743,
# # #'           0.9979,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9995,0.9994,0.9993,0.9993,0.9993,0.9992,0.9993,0# # .9993,0.9993,0.9992,0.9993,0.9992,0.9992,0.9992,0.9993,0.9993,0.9993,0.9992,0.9992,0.9992,0.9992,0# # .9991,0.999,0.9988,0.9986,0.9985,0.9984,0.9982,0.9982,0.9981,0.9977,0.9973,0.9968,0.9967,0.9963,0# # .9957,0.9958,0.9955,0.9947,0.9939,0.9935,0.993,0.9923,0.9914,0.9903,0.9891,0.9879,0.9872,0.9862,0# # .9843,0.982,0.9807,0.9791,0.9766,0.9743,0.9704,0.9665,0.9646,0.9606,0.954,0.9489,0.9427,0.9326,0# # .9246,0.9172,0.9075,0.8967,0.8833,0.8673,0.8531,0.8359,0.817,0.8054,0.784,0.7543,0.7308,0.7135,0# # .6957,0.6731,0.6503,0.6278,0.58,
# # #'           0.9978,0.9994,0.9997,0.9997,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9998,0.9997,0.9997,0.9996,0.9994,0.9994,0.9994,0.9994,0.9992,0.9993,0# # .9994,0.9993,0.9994,0.9993,0.9992,0.9993,0.9993,0.9993,0.9993,0.9992,0.9991,0.9992,0.9991,0.9991,0# # .9992,0.9991,0.999,0.9986,0.9984,0.9984,0.9983,0.9981,0.998,0.9977,0.9972,0.997,0.9968,0.9964,0.996# # ,0.9958,0.9955,0.9946,0.994,0.9936,0.9934,0.9926,0.9914,0.9908,0.9901,0.9885,0.9874,0.9868,0.9857,0# # .9835,0.9818,0.9801,0.9777,0.9748,0.9712,0.968,0.9642,0.9599,0.9554,0.9506,0.9432,0.935,0.9293,0# # .9207,0.9097,0.8971,0.8852,0.8716,0.854,0.8404,0.8243,0.803,0.7838,0.7586,0.728,0.7077,0.693,0.6698# # ,0.6468,0.6233,0.575,
# # #'           0.9977,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9996,0.9995,0.9995,0.9994,0.9993,0.9993,0.9993,0.9992,0# # .9994,0.9994,0.9993,0.9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9994,0.9993,0.9994,0.9994,0.9992,0# # .999,0.9989,0.9989,0.9987,0.9988,0.9988,0.9984,0.9981,0.9978,0.9976,0.9974,0.9972,0.997,0.9966,0# # .9961,0.9957,0.9953,0.9949,0.9946,0.9938,0.993,0.9925,0.9918,0.9909,0.9895,0.9883,0.9876,0.9864,0# # .9857,0.9839,0.9812,0.9796,0.9779,0.9757,0.973,0.9686,0.9652,0.961,0.954,0.949,0.9435,0.9366,0.9294# # ,0.9196,0.9108,0.9006,0.887,0.8732,0.8575,0.8421,0.8245,0.8028,0.7852,0.7671,0.741,0.7179,0.6987,0# # .6757,0.6526,0.6298,0.5808,
# # #'           0.9981,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9996,0.9995,0.9995,0.9994,0.9993,0.9993,0.9993,0.9993,0# # .9994,0.9993,0.9993,0.9993,0.9994,0.9992,0.9993,0.9994,0.9993,0.9993,0.9993,0.9993,0.9993,0.9992,0# # .9991,0.9991,0.9991,0.9989,0.9986,0.9985,0.9985,0.9982,0.9979,0.9976,0.9974,0.9972,0.9972,0.9969,0# # .9964,0.9959,0.9952,0.9952,0.9947,0.9934,0.9931,0.9928,0.9922,0.9915,0.9904,0.989,0.9876,0.9867,0# # .9852,0.9834,0.9819,0.9804,0.9788,0.9763,0.9734,0.9707,0.9659,0.9608,0.9562,0.9509,0.9461,0.9416,0# # .9336,0.9209,0.9098,0.9,0.8881,0.8748,0.8621,0.8474,0.8282,0.8065,0.7817,0.763,0.7445,0.7198,0.6988# # ,0.6753,0.6519,0.6284,0.5786,
# # #'           0.9975,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9997,0.9997,0.9996,0.9995,0.9993,0.9993,0.9993,0.9993,0# # .9992,0.9992,0.9993,0.9993,0.9994,0.9994,0.9994,0.9993,0.9993,0.9993,0.9994,0.9994,0.9992,0.9991,0# # .999,0.999,0.9991,0.999,0.9988,0.9986,0.9985,0.9983,0.9981,0.9978,0.9977,0.9976,0.9972,0.9967,0# # .9962,0.9958,0.9954,0.9952,0.995,0.9944,0.9936,0.9927,0.992,0.9915,0.9907,0.9897,0.9881,0.987,0# # .9865,0.9849,0.9826,0.9814,0.9796,0.976,0.9724,0.9698,0.9668,0.9622,0.9571,0.9525,0.9464,0.9377,0# # .93,0.9225,0.9122,0.9007,0.8877,0.8723,0.8573,0.8414,0.8204,0.8008,0.7855,0.7631,0.7423,0.7212,0# # .6924,0.6687,0.6449,0.6221,0.5723,
# # #'           0.9976,0.9995,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9998,0.9998,0.9999,0.9999,0.9998,0.9997,0.9995,0.9994,0.9994,0.9994,0.9994,0.9993,0.9993,0# # .9993,0.9992,0.9992,0.9992,0.9992,0.9992,0.9992,0.9993,0.9994,0.9994,0.9992,0.999,0.9991,0.9992,0# # .9992,0.999,0.999,0.999,0.9988,0.9986,0.9984,0.9983,0.9983,0.998,0.9975,0.9974,0.9974,0.9967,0.9962# # ,0.9961,0.996,0.9956,0.995,0.9945,0.9937,0.9925,0.9919,0.9913,0.9904,0.9897,0.9885,0.9873,0.9861,0# # .9846,0.9831,0.9812,0.9794,0.9775,0.9742,0.9706,0.9669,0.9635,0.9607,0.9554,0.9482,0.9416,0.9347,0# # .9267,0.9148,0.9034,0.894,0.8806,0.8662,0.8452,0.8279,0.8102,0.7831,0.7623,0.7356,0.7147,0.6972,0# # .6729,0.649,0.6247,0.5746,
# # #'           0.9978,0.9995,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9997,0.9997,0.9996,0.9994,0.9993,0.9994,0.9993,0.9993,0.9993,0# # .9993,0.9994,0.9993,0.9993,0.9992,0.9992,0.9992,0.9991,0.9991,0.9992,0.9993,0.9992,0.9993,0.9993,0# # .9992,0.9991,0.9989,0.9988,0.9987,0.9987,0.9986,0.9984,0.998,0.9978,0.9976,0.9972,0.9973,0.9972,0# # .9969,0.9965,0.996,0.9954,0.995,0.9946,0.9939,0.9929,0.9921,0.9914,0.9909,0.9904,0.9891,0.9874,0# # .9861,0.9848,0.9831,0.9815,0.9801,0.9787,0.9751,0.9712,0.9683,0.9641,0.9599,0.9562,0.9503,0.9433,0# # .9355,0.9263,0.9181,0.9065,0.8934,0.8813,0.8702,0.8525,0.8296,0.8156,0.7995,0.7766,0.7577,0.7371,0# # .7097,0.6864,0.6629,0.6394,0.5885,
# # #'           0.9976,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9995,0.9994,0.9994,0.9994,0.9994,0.9993,0.9991,0# # .9991,0.9992,0.9992,0.9993,0.9993,0.9994,0.9994,0.9992,0.9992,0.9992,0.9991,0.9991,0.9992,0.9993,0# # .9991,0.999,0.9989,0.9989,0.9989,0.9988,0.9988,0.9985,0.9982,0.9981,0.9978,0.9977,0.9973,0.9967,0# # .9964,0.9961,0.9958,0.9954,0.9948,0.9944,0.9939,0.9934,0.9928,0.9917,0.9908,0.9898,0.9885,0.9875,0# # .9868,0.9856,0.984,0.9813,0.9792,0.9781,0.9749,0.9713,0.9693,0.9664,0.9605,0.9552,0.949,0.9427,0# # .9372,0.9288,0.9191,0.9054,0.8918,0.8799,0.8657,0.8477,0.8314,0.814,0.7884,0.767,0.7501,0.7284,0# # .7013,0.6772,0.6533,0.6287,0.5782,
# # #'           0.9978,0.9995,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9999,0.9998,0.9998,0.9997,0.9996,0.9996,0.9995,0.9995,0.9994,0.9995,0.9993,0# # .9992,0.9993,0.9993,0.9994,0.9993,0.9992,0.9991,0.9992,0.9992,0.9992,0.9992,0.9992,0.9992,0.999,0# # .9991,0.9991,0.9988,0.9988,0.9988,0.9988,0.9986,0.9984,0.9983,0.9979,0.9978,0.9977,0.9976,0.9974,0# # .9967,0.9962,0.9959,0.9958,0.9955,0.9949,0.9941,0.993,0.992,0.9918,0.991,0.99,0.9888,0.9874,0.9866# # ,0.9855,0.9839,0.9821,0.9802,0.9775,0.9757,0.9738,0.9693,0.9656,0.9612,0.9563,0.9508,0.9438,0.9375# # ,0.9309,0.9202,0.9081,0.8966,0.8827,0.8714,0.8598,0.8396,0.8147,0.7931,0.772,0.7499,0.7294,0.7059,0# # .6818,0.6574,0.6333,0.5815,
# # #'           0.9979,0.9996,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9999,0.9998,0.9999,0.9998,0.9996,0.9995,0.9995,0.9995,0.9994,0.9993,0.9993,0.9992,0# # .9993,0.9993,0.9991,0.9992,0.9992,0.9993,0.9993,0.9992,0.9993,0.9994,0.9991,0.9991,0.9992,0.9991,0# # .9989,0.9989,0.999,0.9989,0.9988,0.9987,0.9986,0.9986,0.9985,0.9981,0.998,0.9979,0.9974,0.9972,0# # .997,0.9965,0.9961,0.9956,0.9955,0.9953,0.9946,0.994,0.9932,0.9917,0.9903,0.9901,0.9895,0.9883,0# # .9877,0.9857,0.9834,0.9828,0.9815,0.979,0.9768,0.9747,0.9716,0.9667,0.9611,0.9571,0.9539,0.9471,0# # .9387,0.9296,0.9189,0.9088,0.8982,0.8842,0.8669,0.847,0.8249,0.8068,0.7907,0.7732,0.7507,0.7199,0# # .6941,0.6689,0.6435,0.6187,0.5669,
# # #'           0.9981,0.9996,0.9998,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0.9999,0# # .9999,0.9999,0.9998,0.9998,0.9999,0.9997,0.9996,0.9996,0.9996,0.9994,0.9993,0.9994,0.9993,0.9993,0# # .9994,0.9993,0.9992,0.9993,0.9993,0.9994,0.9994,0.9993,0.9992,0.9991,0.9992,0.9992,0.9992,0.9992,0# # .999,0.999,0.999,0.999,0.9988,0.9988,0.9987,0.9985,0.9985,0.9983,0.9979,0.9978,0.9975,0.997,0.9969# # ,0.9968,0.9964,0.996,0.9956,0.9949,0.9941,0.9935,0.9928,0.9921,0.9912,0.99,0.9888,0.9877,0.9867,0# # .9856,0.9839,0.9826,0.9807,0.9793,0.9773,0.9739,0.9704,0.9663,0.9632,0.9589,0.953,0.9456,0.9376,0# # .9295,0.9208,0.9115,0.8987,0.8831,0.8685,0.8532,0.8322,0.8139,0.7997,0.7768,0.7487,0.7253,0.7054,0# # .681,0.6567,0.6329,0.5804)
# # #'
# # #'
# # #' all_years <- c("1999", "2000", "2001", "2002", "2003", "2004",
# # #'                "2005", "2006", "2007", "2008", "2009", "2010",
# # #'                "2011", "2012", "2013", "2014", "2015", "2016",
# # #'                "2017", "2018", "2019")
# # #'
# # #' # Population for males as matrix
# # #' pop_m_mat <- matrix(pop_m, nrow = 101, ncol = 21)
# # #' colnames(pop_m_mat) <- all_years
# # #'
# # #' # Population for females as matrix
# # #' pop_f_mat <- matrix(pop_f, nrow = 101, ncol = 21)
# # #' colnames(pop_f_mat) <- all_years
# # #'
# # #' # Age-specific-fertility-rate for as matrix
# # #' asfr_mat <- matrix(asfr, nrow = 35, ncol = 20)
# # #' colnames(asfr_mat) <- all_years[-length(all_years)]
# # #'
# # #' # Sex ratio at birth as vector
# # #' srb_vec <- c(1.06,	1.06,	1.06,	1.06,	1.06, 1.06,	1.06,	1.06,	1.06, 1.06,
# # #'  1.06,	1.06,	1.06,	1.06,	1.06, 1.06,	1.06,	1.06,	1.06,	1.06, 1.06)
# # #'
# # #'
# # #' names(srb_vec) <- all_years[-length(all_years)]
# # #'
# # #' # Survival ratio for males as matrix
# # #' sr_m_mat <- matrix(sr_m, nrow = 101, ncol = 20)
# # #' colnames(sr_m_mat) <- all_years[-length(all_years)]
# # #'
# # #' # Survival ratio for females as matrix
# # #' sr_f_mat <- matrix(sr_f, nrow = 101, ncol = 20)
# # #' colnames(sr_f_mat) <- all_years[-length(all_years)]
# # #'
# # #' # Age/year sequence of all the data from above
# # #' interval <- 1
# # #' ages <- seq(0, 100, by = interval)
# # #' years <- seq(1999, 2019, by = interval)
# # #' ages_asfr <- seq(15, 50, by = interval)
# # #' #'
# # #' mig_res <-
# # #'   mig_resid_stock(
# # #'   pop_m_mat = pop_m_mat,
# # #'   pop_f_mat = pop_f_mat,
# # #'   sr_m_mat = sr_m_mat,
# # #'   sr_f_mat = sr_f_mat,
# # #'   asfr_mat = asfr_mat,
# # #'   srb_vec = srb_vec,
# # #'   ages = ages,
# # #'   ages_asfr = ages_asfr
# # #'   )
# # #'
# # #' # Net migration for males using stock change method
# # #' mig_res$mig_m
# # #'
# # #' # Net migration for females using stock change method
# # #' mig_res$mig_f
# # #'
# # #'
# # #' ################ cohort even flow method  #####################
# # #'
# # #' # We reuse the same data from before
# # #'
# # # mig_res <-
# # #   mig_resid_cohort(
# # #     pop_m_mat = pop_m_mat,
# # #     pop_f_mat = pop_f_mat,
# # #     sr_m_mat = sr_m_mat,
# # #     sr_f_mat = sr_f_mat,
# # #     asfr_mat = asfr_mat,
# # #     srb_vec = srb_vec,
# # #     ages = ages,
# # #     ages_asfr = ages_asfr
# # #   )
# # #'
# # #' # Net migration for males using the cohort even flow method
# # #' mig_res$mig_m
# # #'
# # #' # Net migration for females using the cohort even flow method
# # #' mig_res$mig_f
# # #'
# # #' ################ time even flow method  #####################
# # #'
# # #' # We reuse the same data from before
# # #'
# # #' mig_res <-
# # #'   mig_resid_time(
# # #'     pop_m_mat = pop_m_mat,
# # #'     pop_f_mat = pop_f_mat,
# # #'     sr_m_mat = sr_m_mat,
# # #'     sr_f_mat = sr_f_mat,
# # #'     asfr_mat = asfr_mat,
# # #'     srb_vec = srb_vec,
# # #'     ages = ages,
# # #'     ages_asfr = ages_asfr
# # #'   )
# # #'
# # #' # Net migration for males using the time even flow method
# # #' mig_res$mig_m
# # #'
# # #' # Net migration for females using the time even flow method
# # #' mig_res$mig_f
# # #'
# # #' @export
# # mig_resid_stock <- function(pop_m_mat,
# #                             pop_f_mat,
# #                             sr_m_mat,
# #                             sr_f_mat,
# #                             asfr_mat,
# #                             srb_vec,
# #                             ages,
# #                             ages_asfr) {
# # 
# #   stopifnot(
# #     is.matrix(pop_m_mat), # the function works just with this objects
# #     is.matrix(pop_f_mat),
# #     is.matrix(sr_m_mat),
# #     is.matrix(sr_f_mat),
# #     is.matrix(asfr_mat),
# #     is.numeric(srb_vec),
# #     is.numeric(ages),
# #     is.numeric(ages_asfr)
# #   )
# # 
# #   # Migration net of only survivors
# #   net_mig_m <- migresid_net_surv(pop_m_mat, sr_m_mat)
# #   net_mig_f <- migresid_net_surv(pop_f_mat, sr_f_mat)
# # 
# #   fertility_index <- which(ages %in% ages_asfr)
# # 
# #   # Returns all births for all years
# #   age_interval <- unique(diff(ages))
# #   all_births <- migresid_births(
# #     pop_f_mat,
# #     asfr_mat,
# #     fertility_index,
# #     age_interval
# #   )
# # 
# #   # With all_births already calculated, separate between
# #   # female/male births with the sex ratio at birth
# #   births_m <- all_births[2:length(all_births)] * (srb_vec / (1 + srb_vec))
# #   births_f <- all_births[2:length(all_births)] * (1 / (1 + srb_vec))
# # 
# #   net_mig_m <- migresid_net_surv_first_ageg(
# #     net_mig_m,
# #     pop_m_mat,
# #     births_m,
# #     sr_m_mat
# #   )
# # 
# #   net_mig_f <- migresid_net_surv_first_ageg(
# #     net_mig_f,
# #     pop_f_mat,
# #     births_f,
# #     sr_f_mat
# #   )
# # 
# #   # First year is empty, so we exclude
# #   list(
# #     mig_m = net_mig_m[, -1],
# #     mig_f = net_mig_f[, -1]
# #   )
# # }
# # 
# # #' @rdname mig_resid_stock
# # #' @export
# # mig_resid_cohort <- function(pop_m_mat,
# #                              pop_f_mat,
# #                              sr_m_mat,
# #                              sr_f_mat,
# #                              asfr_mat,
# #                              srb_vec,
# #                              ages,
# #                              ages_asfr) {
# # 
# #   # Estimate stock method
# #   mig_res <-
# #     mig_resid_stock(
# #       pop_m_mat = pop_m_mat,
# #       pop_f_mat = pop_f_mat,
# #       sr_m_mat = sr_m_mat,
# #       sr_f_mat = sr_f_mat,
# #       asfr_mat = asfr_mat,
# #       srb_vec = srb_vec,
# #       ages = ages,
# #       ages_asfr = ages_asfr
# #     )
# # 
# #   net_mig_m <- mig_res$mig_m
# #   net_mig_f <- mig_res$mig_f
# # 
# #   # Estimate bounds for males
# #   mig_m_bounds <- migresid_bounds(net_mig_m, sr_m_mat)
# #   mig_upper_m <- mig_m_bounds$upper
# #   mig_lower_m <- mig_m_bounds$lower
# # 
# #   # Estimate bounds for females
# #   mig_f_bounds <- migresid_bounds(net_mig_f, sr_f_mat)
# #   mig_upper_f <- mig_f_bounds$upper
# #   mig_lower_f <- mig_f_bounds$lower
# # 
# #   # Adjust last age group in the bounds
# #   mig_bounds <- migresid_bounds_last_ageg(
# #     net_mig_m,
# #     net_mig_f,
# #     mig_upper_m,
# #     mig_lower_m,
# #     mig_upper_f,
# #     mig_lower_f
# #   )
# # 
# #   mig_upper_m <- mig_bounds$mig_upper_m
# #   mig_lower_m <- mig_bounds$mig_lower_m
# #   mig_upper_f <- mig_bounds$mig_upper_f
# #   mig_lower_f <- mig_bounds$mig_lower_f
# # 
# #   # Combine both upper/lower bound into a single rectangle
# #   mig_rectangle_m <- mig_upper_m + mig_lower_m
# #   mig_rectangle_f <- mig_upper_f + mig_lower_f
# # 
# #   list(
# #     mig_m = mig_rectangle_m[, -1],
# #     mig_f = mig_rectangle_f[, -1]
# #   )
# # }
# # 
# # #' @rdname mig_resid_stock
# # #' @export
# # mig_resid_time <- function(pop_m_mat,
# #                            pop_f_mat,
# #                            sr_m_mat,
# #                            sr_f_mat,
# #                            asfr_mat,
# #                            srb_vec,
# #                            ages,
# #                            ages_asfr) {
# # 
# #   # Estimate stock method
# #   mig_res <-
# #     mig_resid_stock(
# #       pop_m_mat = pop_m_mat,
# #       pop_f_mat = pop_f_mat,
# #       sr_m_mat = sr_m_mat,
# #       sr_f_mat = sr_f_mat,
# #       asfr_mat = asfr_mat,
# #       srb_vec = srb_vec,
# #       ages = ages,
# #       ages_asfr = ages_asfr
# #     )
# # 
# #   # Separate male/female net migration
# #   net_mig_m <- mig_res$mig_m
# #   net_mig_f <- mig_res$mig_f
# # 
# #   # Adjust age group 0-4
# #   net_mig_m[1, ] <- 2 * net_mig_m[1, ]
# #   net_mig_f[1, ] <- 2 * net_mig_f[1, ]
# # 
# #   # Adjust age groups 5-10  to 100+ (of whatever maximum age groups)
# #   for (i in 2:nrow(net_mig_m)) {
# #     double_pop_m <- (2 * net_mig_m[i, ])
# #     double_pop_f <- (2 * net_mig_f[i, ])
# # 
# #     # Multiply net mig of i - 1 by survival rate of i
# #     # to get number of survived
# #     mig_sr_m <- net_mig_m[i - 1, ] * sr_m_mat[i, ]
# #     mig_sr_f <- net_mig_f[i - 1, ] * sr_f_mat[i, ]
# # 
# #     net_mig_m[i, ] <- double_pop_m - mig_sr_m
# #     net_mig_f[i, ] <- double_pop_f - mig_sr_f
# #   }
# # 
# #   list(
# #     mig_m = net_mig_m,
# #     mig_f = net_mig_f
# #   )
# # }
# # 
# # 
# # # Net migration is pop minus the people that survived from the previous
# # # age/cohort
# # migresid_net_surv <- function(pop_mat, sr_mat) {
# #   n <- nrow(pop_mat)
# #   p <- ncol(pop_mat)
# #   survived <-
# #     pop_mat[-n, -p] * #eliminate the last year and age-group and then its is multiplied by survival # # rates matrix
# #     sr_mat[-1, ] #remove last age-group
# #   res <- pop_mat[-1, -1] - survived #pop from the last year - survived = residual
# #   res[nrow(res), ] <- NA # recode last row (last age group) as na
# #   res <- rbind(matrix(NA, nrow = 1, ncol = ncol(res)), res) # add a first row as NA and push the # # original to the 2nd row
# #   res <- cbind(matrix(NA, nrow = nrow(res), ncol = 1), res) # add a first col with NA values
# #   res <- migresid_net_surv_last_ageg(res, pop_m_mat, sr_m_mat) #applying a special function to the # # last age-group
# #   res
# # }
# # 
# # # Net migration for last age group is pop for that age group in
# # # year j, minus the people from the previous age group the survived
# # migresid_net_surv_last_ageg <- function(net_mig, pop_mat, sr_mat) {
# #   n <- nrow(pop_mat)
# #   p <- ncol(pop_mat)
# #   previous_year <- 1:(p - 1)
# #   survived <-
# #     (pop_mat[n, previous_year] + pop_mat[n - 1, previous_year]) * #pop in the last row (agegroup) # # in all years but the last column +
# #     sr_mat[n, previous_year]
# # 
# #   net_mig[nrow(net_mig), 2:ncol(net_mig)] <- pop_mat[n, 2:p] - survived
# #   net_mig
# # }
# # # Births from
# # migresid_births <- function(pop_f_mat,
# #                             asfr_mat,
# #                             fertility_index,
# #                             age_interval) {
# #   p <- ncol(pop_f_mat)
# # 
# #   # Sum female pop from previous year and this year
# #   f_pop <- pop_f_mat[fertility_index, -1] + pop_f_mat[fertility_index, -p] # f pop 1950+1955 / 1955# # -1960...
# # 
# #   # Births that occurred for all age groups for all years
# #   # based on the age-specific fertility rate (asfr) from
# #   # previous years to the population
# #   these_births <- age_interval * (0.5 * (f_pop) * asfr_mat[, -p])/1000
# # 
# #   all_births <- c(NA, colSums(these_births))
# #   col_names <- attr(pop_f_mat, "dimnames")[[2]]
# #   all_births <- stats::setNames(all_births, col_names)
# #   all_births
# # }
# # 
# # migresid_net_surv_first_ageg <- function(net_mig, pop_mat, births, sr_mat) {
# #   p <- ncol(net_mig)
# #   net_mig[1, 2:p] <- pop_mat[1, 2:p] - births * sr_mat[1, ]
# #   net_mig
# # }
# # 
# # 
# # # Returns age/year matrices with upper/lower bounds
# # # for net migration based on the net migration and
# # # survival rates. These, I believe are the upper/lower
# # # bounds of a lexis surfave (which is why we do ^0.5).
# # migresid_bounds <- function(net_mig, sr_mat) {
# #   n <- nrow(net_mig)
# #   p <- ncol(net_mig)
# # 
# #   # Upper bound is net mig / 2 times the survival ratio ^ 0.5
# #   mig_upper <- net_mig / (2 * sr_mat^0.5)
# #   mig_upper <- cbind(matrix(NA, ncol = 1, nrow = n), mig_upper)
# #   mig_lower <- mig_upper
# #   mig_upper[1, ] <- NA
# #   mig_upper[n, ] <- NA
# #   mig_lower[n, ] <- NA
# #   mig_lower <- mig_lower[-1, ]
# #   empty_matrix <- matrix(NA, ncol = ncol(mig_lower), nrow = 1)
# #   mig_lower <- rbind(mig_lower, empty_matrix)
# # 
# #   # Estimate upper bounds for the first age group. Why
# #   # no lower bound for the first age group? because we have
# #   # no previous age group.
# #   p_upper <- ncol(mig_upper)
# #   mig_upper[1, 2:p_upper] <- net_mig[1, -p_upper] / (sr_mat[1, -p_upper]^0.5)
# # 
# #   list(upper = mig_upper, lower = mig_lower)
# # }
# # 
# # # Updates last age group for all upper/lower bounds
# # migresid_bounds_last_ageg <- function(net_mig_m,
# #                                       net_mig_f,
# #                                       mig_upper_m,
# #                                       mig_lower_m,
# #                                       mig_upper_f,
# #                                       mig_lower_f) {
# # 
# # 
# #   # last age group
# #   n <- nrow(mig_upper_m) ## n is equal the number of rows in mig_upper_m
# #   p <- ncol(mig_upper_m) ## p is equal the number of cols in mig_upper_m
# # 
# #   mig_lower_m[n - 1, ] <- mig_upper_m[n - 1, ]
# #   mig_lower_f[n - 1, ] <- mig_upper_f[n - 1, ]
# #   mig_upper_m[n, 2:p] <- net_mig_m[n, -p] * 0.5
# #   mig_upper_f[n, 2:p] <- net_mig_f[n, -p] * 0.5
# #   mig_lower_m[n, 2:p] <- net_mig_m[n, -p] * 0.5
# #   mig_lower_f[n, 2:p] <- net_mig_f[n, -p] * 0.5
# # 
# #   list(
# #     mig_lower_m = mig_lower_m,
# #     mig_upper_m = mig_upper_m,
# #     mig_lower_f = mig_lower_f,
# #     mig_upper_f = mig_upper_f
# #   )
# # }
# # 
timriffe/DemoTools documentation built on Jan. 28, 2024, 5:13 a.m.