old_code/draw_xk.R

draw_xk_noreg <- function(rate_im1, rate_im2, rate_em1, rate_em2, stock_start, count_dth) {
    exposure <- 0.5 * count_dth
    ## generate combined net migration
    mu_im <- rate_im1 + rate_im2
    mu_em <- (rate_em1 + rate_em2) * exposure
    lower_bound_mig <- stock_start - count_dth
    net_mig <- rskeltr(mu1 = mu_im,
                       mu2 = mu_em,
                       lower = lower_bound_mig)
    ## derive stock at end of period
    stock_end <- stock_start - count_dth + net_mig
    ## split combined net migration into components
    gross_mig <- rpoistr(lambda = mu_im + mu_em,
                         lower = net_mig)
    count_im <- (gross_mig + net_mig) %/% 2L
    count_em <- (gross_mig - net_mig) %/% 2L
    prob_im1 <- rate_im1 / (rate_im1 + rate_im2)
    prob_em1 <- rate_em1 / (rate_em1 + rate_em2)
    count_im1 <- rbinom(n = 1L,
                        size = count_im,
                        prob = prob_im1)
    count_em1 <- rbinom(n = 1L,
                        size = count_em,
                        prob = prob_em1)
    count_im2 <- count_im - count_im1
    count_em2 <- count_em - count_em2
    ans <- c(stock_end,
             count_im1,
             count_im2,
             count_em1,
             count_em2)
    ans
}

    
    
    
    
ONSdigital/Bayesian-demographic-accounts documentation built on Jan. 10, 2022, 12:34 a.m.