Given a set of ages and observed age-specific migration rates, estimate the parameters of a Roger-Castro model migration schedule. Choose between a 7,9,11 or 13 parameter model.
mig_estimate_rc( ages, mx, pre_working_age, working_age, retirement, post_retirement, ... )
ages | numeric. A vector of ages. |
---|---|
mx | numeric. A vector of observed age-specific migration rates. |
pre_working_age | logical (TRUE/FALSE). Whether or not to include pre working age component. |
working_age | logical (TRUE/FALSE). Whether or not to include working age component. |
retirement | logical (TRUE/FALSE). Whether or not to include retirement age component. |
post_retirement | logical (TRUE/FALSE). Whether or not to include post retirement age component. |
... | additional inputs to stan, see ?rstan::stan for details. |
if (FALSE) { # define ages and migration rates ages <- 0:75 mig_rate <- c(0.1014,0.0984,0.0839,0.0759,0.0679,0.0616, 0.055,0.0518,0.0438,0.0399,0.0363,0.0342,0.0307,0.0289, 0.0267,0.0237,0.0283,0.0294,0.0392,0.0547,0.068,0.0933, 0.1187,0.1282,0.1303,0.1293,0.1247,0.1163,0.1059,0.0976, 0.09,0.0817,0.0749,0.0683,0.0626,0.058,0.0536,0.0493, 0.0459,0.0418,0.0393,0.0358,0.0343,0.0322,0.0298,0.0281, 0.0266,0.0248,0.0235,0.0222,0.0208,0.0191,0.0178,0.0171, 0.0157,0.0149,0.0139,0.0132,0.012,0.0112,0.0116,0.0106, 0.0102,0.0109,0.0107,0.0143,0.0135,0.0134,0.0116,0.0099, 0.0093,0.0083,0.0078,0.0067,0.0069,0.0054) # fit the model res <- mig_estimate_rc(ages, mig_rate, pre_working_age = TRUE, working_age = TRUE, retirement = FALSE, post_retirement = FALSE) # plot the results and data plot(ages, mig_rate, ylab = "migration rate", xlab = "age") lines(ages, res[["fit_df"]]$median, col = "red") legend("topright", legend=c("data", "fit"), col=c("black", "red"), lty=1, pch = 1) }