ccmpp_c: R wrapper for the _C_ function 'C_ccmpp'.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/projection_functions.R

Description

This is a simple wrapper for the _C_ function of the same name which performs population projection by the cohort component method (see the documentation for ccmpp). The _C_ function can be loaded for use in _C_ source code via #include ccmppAPI. The arguments are documented here for both functions. Argument types for _C_ are given in parentheses in the argument list.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ccmpp_c(
  out_pop_fem,
  out_pop_male,
  srb,
  fert,
  surv_fem,
  surv_male,
  surv_fem_0,
  surv_male_0,
  mig_fem,
  mig_male,
  bline_fem,
  bline_male,
  n_proj_steps,
  n_age_pop,
  step_wid
)

Arguments

out_pop_fem

(double *out_pop_fem) In R this is an n_age_pop * (1 + proj_steps) matrix with age groups as rows and time periods as columns. In _C_ it is an array of length n_age_pop * (1 + proj_steps). Its first column (in R), or first n_age_pop entries (in _C_) contain bline_fem, the age-specific female population counts in the year that marks the start of the projection (the “baseline”). The rest of the entries are arbitrary; they serve as a repository for the results which will overrite whatever entries are supplied. See “Details”.

out_pop_male

(double *out_pop_male) Same as out_pop_fem but for males.

srb

(double *srb) Vector of length n_proj_steps containing the average sex ratios at birth.

fert

(double *fert) Average annual age-specific fertility rates for each of the n_proj_steps. In R this can be supplied as a matrix with age groups as rows and time periods as columns. In _C_ it is an array of length n_age_pop * proj_steps formed by concatenating the age-specific fertility rates for each projection period.

surv_fem

(double *surv_fem) Age-specific survival proportions for females for ages 5 to the open ended age group. Like fert, in R it can be supplied as an n_age_pop by n_proj_steps matrix with age groups as rows. If using the _C_ version it should be an array with n_age_pop * n_proj_steps elements.

surv_male

(double *surv_male) Same as surv_fem but for males.

surv_fem_0

(double *surv_fem_0) Vector of lenght n_proj_steps containing survival proportions of females for the period birth to the end of the first projection interval, for each period in the projection.

surv_male_0

(double *surv_male_0) Same as surv_fem_0 but for males.

mig_fem

(double *mig_fem) A matrix (in R) or vector (in _C_) with the same dimensions as for fert but containing average annual net migrations for females as a proportion of the receiving population, by age.

mig_male

(double *mig_male) Same as mig_fem but for males.

bline_fem

(double *bline_fem) A vector of age-specific female population counts in the year that marks the start of the projection (the “baseline”).

bline_male

(double *bline_male) Same as bline_fem but for males.

n_proj_steps

(int *n_proj_steps) The number of steps to project forward. This must conform to the dimensions of the other inputs; see where this argument is mentioned in their descriptions. No checking is done to make sure this condition is satisfied.

n_age_pop

(int *n_age_pop) The number of age groups in the projection. As for n_proj_steps, this must conform to the dimensions of the other inputs; see where this argument is mentioned in their descriptions. No checking is done to make sure this condition is satisfied.

step_wid

(int *step_wid) The scale of the projection intervals, e.g., in years.

Details

The _C_ code is accessed via .C hence all arguments are passed via pointers. In particular, the first two arguments are containers for the output. They must be vectors of length n_age_pop which can be coerced via as.double. The values of the elements are unimportant as they will be overwritten with the output; e.g., you could supply the same value to out_pop_fem as bline_fem (and similarly for the male versions), as in the example.

Value

In R, a two-element list containig the first two arguments with their (n_age_pop + 1), (n_age_pop + 2), ..., elements replaced with the projected counts for females and males, respectiely. The _C_ function returns nothing (void) but has the side effect of similarly replacing element in the first two arguments.

Author(s)

Mark C Wheldon

See Also

ccmpp, a more friendly wrapper for the same underlying _C_ function that takes arguments as R lists and does some optional input checks.

Other CCMPP backend functions: ccmpp_r()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)))

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