calc_asfr: Calculate age-specific fertility rate (ASFR) and total...

View source: R/fertility.R

calc_asfrR Documentation

Calculate age-specific fertility rate (ASFR) and total fertility rate (TFR)

Description

Calculate age-specific fertility rate (ASFR) and total fertility rate (TFR)

Usage

calc_asfr(
  data,
  by = NULL,
  agegr = 3:10 * 5,
  period = NULL,
  cohort = NULL,
  tips = c(0, 3),
  clusters = ~v021,
  strata = ~v024 + v025,
  id = "caseid",
  dob = "v011",
  intv = "v008",
  weight = "v005",
  varmethod = "lin",
  bvars = grep("^b3\\_[0-9]*", names(data), value = TRUE),
  birth_displace = 1e-06,
  origin = 1900,
  scale = 12,
  bhdata = NULL,
  counts = FALSE,
  clustcounts = FALSE
)

Arguments

data

A dataset (data.frame), for example a DHS individual recode (IR) dataset.

by

A formula specifying factor variables by which to stratify analysis.

agegr

Numeric vector defining ages in years for splits.

period

Numeric vector defining calendar periods to stratify analysis, use NULL for no periods.

cohort

Numeric vector defining birth cohorts to stratify analysis, use NULL for no cohort stratification.

tips

Break points for TIme Preceding Survey.

clusters

Formula or data frame specifying cluster ids from largest level to smallest level, ‘~0’ or ‘~1’ is a formula for no clusters.

strata

Formula or vector specifying strata, use ‘NULL’ for no strata.

id

Variable name for identifying each individual respondent (character string).

dob

Variable name for date of birth of each individual (character string).

intv

Variable name for interview date (character string).

weight

Formula or vector specifying sampling weights.

varmethod

Method for variance calculation. Currently "lin" for Taylor linearisation or "jk1" for unstratified jackknife, or "jkn", for stratified jackknife.

bvars

Names of variables giving child dates of birth. If bhdata is provided, then length(bvars) must equal 1.

birth_displace

Numeric value to displace multiple births date of birth by. Default is '1e-6'.

origin

Origin year for date arguments. 1900 for CMC inputs.

scale

Scale for dates inputs to calendar years. 12 for CMC inputs.

bhdata

A birth history dataset (data.frame) with child dates of birth in long format, for example a DHS births recode (BR) dataset.

counts

Whether to include counts of births & person-years ('pys') in the returned data.frame. Default is 'FALSE'.

clustcounts

Whether to return additional attributes storing cluster specific counts of births attr(val, 'events_clust'), person-years attr(val, 'pyears_clust') & number of clusters in each strata attr(val, 'strataid'). Only applicable when using jacknife varmethod 'jk1' or 'jkn'. 'strataid' is only included for 'jkn' varmethod. Default is 'FALSE'.

Details

Events and person-years are calculated using normalized weights. Unweighted aggregations may be output by specifying weights=NULL (default) or weights=~1.

The assumption is that all dates in the data are specified in the same format, typically century month code (CMC). The period argument is specified in calendar years (possibly non-integer).

Default values for agegr, period, and tips parameters returns age-specific fertility rates over the three-years preceding the survey, the standard fertility indicator produced in DHS reports.

Value

A data.frame consisting of estimates and standard errors. The full covariance matrix of the estimates can be retrieved by vcov(val).

See Also

demog_pyears()

Examples

data(zzir)

## Replicate DHS Table 5.1
## ASFR and TFR in 3 years preceding survey by residence
calc_asfr(zzir, ~1, tips=c(0, 3))
reshape2::dcast(calc_asfr(zzir, ~v025, tips=c(0, 3)), agegr ~ v025, value.var = "asfr")
calc_tfr(zzir, ~v025)
calc_tfr(zzir, ~1)

## Replicate DHS Table 5.2
## TFR by resdience, region, education, and wealth quintile
calc_tfr(zzir, ~v102)  # residence
calc_tfr(zzir, ~v101)  # region
calc_tfr(zzir, ~v106)  # education
calc_tfr(zzir, ~v190)  # wealth
calc_tfr(zzir)         # total

## Calculate annual TFR estimates for 10 years preceding survey
tfr_ann <- calc_tfr(zzir, tips=0:9)

## Sample covariance of annual TFR estimates arising from complex survey design
cov2cor(vcov(tfr_ann))

## Alternately, calculate TFR estimates by calendar year
tfr_cal <- calc_tfr(zzir, period = 2004:2015, tips=NULL)
tfr_cal

## sample covariance of annual TFR estimates arising from complex survey design
## Generate estimates split by period and TIPS
cov2cor(vcov(tfr_cal))

calc_tfr(zzir, period = c(2010, 2013, 2015), tips=0:5)

## ASFR estimates by birth cohort
asfr_coh <- calc_asfr(zzir, cohort=c(1980, 1985, 1990, 1995), tips=NULL)
reshape2::dcast(asfr_coh, agegr ~ cohort, value.var = "asfr")


mrc-ide/demogsurv documentation built on March 21, 2022, 9:49 p.m.