knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## set global chunk options
options(formatR.arrow=TRUE,width=80)

This vignette can be accessed by calling \verb|vignette("Thailand projection", package = "CCMPP")|.

Description

This package implements the cohort-component method of population projection (CCMPP) (@lewis_generation_1942, @leslie_further_1948, @leslie_use_1945) in both R and C. It is based on the 'female-dominant' version given in @preston_demography_2001, Ch. 6, for the kind of input data commonly available in human populations. The CCMPP produces projections of a population by age and sex at discrete points in time, such as every year or every five years. The resolution of age must match the step width (e.g., five-year age groups yields projections at five-year intervals).

Data Included

This package includes example demographic data for Thailand for the period 1960--2000. These are based on input data used to produce the World Population Prospects: the 2010 Revision (@united_nations_world_2011). All parameters are by five-year age group and five-year period. Sex-specific parameters are lists with components male and female. The name of the data set is Thailand_demog which is a list with the following components:

| Component | Description | |:-----------------------|:-------------------------------------------------------------------------------------------------------------| | thai_base_pop_counts | List of population counts in 1960. | | thai_fert_rates | A matrix (age x year) of age-specific fertility rates. | | thai_surv_props | Survivorship proportions (i.e., the proportion surviving five years, or ${}_nS_5$, in demographic notation). | | thai_mig_props | Average annual net number of migrants. | | thai_srb | Average sex ratio at birth. |

data(Thailand_demog, package = "ccmpp")
str(Thailand_demog)
#> List of 5
#>  $ thai_base_pop_counts:List of 2
#>   ..$ female: num [1:17, 1] 2338000 1857000 1543000 1287000 1250000 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:17] "0" "5" "10" "15" ...
#>   .. .. ..$ : chr "1960"
#>   ..$ male  : num [1:17, 1] 2418000 1909000 1588000 1342000 1254000 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:17] "0" "5" "10" "15" ...
#>   .. .. ..$ : chr "1960"
#>  $ thai_fert_rates     : num [1:17, 1:8] 0 0 0 0.0518 0.2402 ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:17] "0" "5" "10" "15" ...
#>   .. ..$ : chr [1:8] "1960" "1965" "1970" "1975" ...
#>  $ thai_surv_props     :List of 2
#>   ..$ female: num [1:18, 1:8] 0.914 0.961 0.99 0.992 0.988 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:18] "0" "5" "10" "15" ...
#>   .. .. ..$ : chr [1:8] "1960" "1965" "1970" "1975" ...
#>
#> [TRUNCATED]

Main Functions

R Level

There are two main functions. ccmpp() and ccmpp_r(). They both take the same arguments and return the same results but the first one uses an implementation of the core arithmetic in C whereas the latter is written entirely in R.

C Level

The C level function is C_ccmpp and is defined in the header 'ccmppAPI.h'. This can be #includeed and used in your own C code. A basic R wrapper called ccmpp_c is provided.

Examples

The population of Thailand is projected from 1960 to 2000 as follows.

library(ccmpp)
data(Thailand_demog)

with(Thailand_demog,
     ccmpp(thai_base_pop_counts,
           surv_props = thai_surv_props,
           fert_rates=thai_fert_rates,
           srb = thai_srb, mig_props = thai_mig_props))

The basic wrapper takes slightly different arguments.

data("Thailand_demog")
raw <-
  with(Thailand_demog, {
  ccmpp_c(out_pop_fem = matrix(rep(thai_base_pop_counts$female, 9), ncol = 9),
          out_pop_male = matrix(rep(thai_base_pop_counts$male, 9), ncol = 9),
          srb = thai_srb,
          fert = thai_fert_rates,
          surv_fem = thai_surv_props$female[-1,],
          surv_male = thai_surv_props$male[-1,],
          surv_fem_0 = thai_surv_props$female[1,],
          surv_male_0 = thai_surv_props$male[1,],
          mig_fem = thai_mig_props$female,
          mig_male = thai_mig_props$male,
          bline_fem = thai_base_pop_counts$female,
          bline_male = thai_base_pop_counts$male,
          n_proj_steps = ncol(thai_fert_rates), #8
          n_age_pop = nrow(thai_base_pop_counts$female), #17
          step_wid = 5
  )})
(nicer <- list(female = matrix(raw[[1]], ncol = 9),
              male = matrix(raw[[2]], ncol = 9)))

References {-}



markalava/CCMPP documentation built on April 29, 2020, 10:53 a.m.