extractCohort: Extract cohort from an age-period array

Description Usage Arguments Value See Also Examples

View source: R/exportUtils.R

Description

Extract cohorts from an age-period array. This is useful to construct a life table or to perform actuarial/demographic calculations on a cohort basis using the output of several functions in StMoMo.

Usage

1
2
extractCohort(A, age = as.numeric(dimnames(A)[[1]][1]),
  period = as.numeric(dimnames(A)[[2]][1]), cohort = period - age)

Arguments

A

an age-period array with a demographic quantity. This array can have two or more dimensions, with the first dimension being the age and the second dimension being the period (calendar year). Note that the names of these two dimension are taken to represent the possible ages and periods in the array.

age

optional age for defining the cohort to be extracted. If argument age is provided (and argument cohort is not) then the extracted cohort corresponds to those born in the year period-age.

period

optional period (calendar year) for defining the cohort to be extracted. If argument period is provided (and argument cohort is not) then the extracted cohort corresponds to those born in the year period-age.

cohort

optional cohort to be extracted. If this argument is provided then arguments age and period are ignored.

Value

If the the input array is two dimensional the the output is a a vector with the quantity along the cohort. Otherwise if A is an N-dimensional array the output is an (N-1)-dimensional array with the first dimension representing the cohort.

See Also

fitted.fitStMoMo, forecast.fitStMoMo, simulate.fitStMoMo, simulate.bootStMoMo

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
LCfit <- fit(lc(), data = EWMaleData, ages.fit = 55:89)
#Plot forecast mortality rates for the 1950 cohort
LCfor <- forecast(LCfit)
plot(55:61, extractCohort(fitted(LCfit, type = "rates"), cohort = 1950), 
     type = "l", log = "y", xlab = "age", ylab = "Mortality rate", 
     main = "Mortality rates for the 1950 cohort", 
     xlim = c(55,89), ylim = c(0.005, 0.12))
lines(62:89, extractCohort(LCfor$rates, cohort = 1950), lty = 2, col = "blue")


#Plot 10 simulated sets of mortality rates for the cohort 
# aged 60 in year 2010 (i.e., the 1950 cohort)
LCsim <- simulate(LCfit, nsim = 10)
mSim <- extractCohort(LCsim$rates, age = 60, period = 2010)
plot(55:61, extractCohort(fitted(LCfit, type = "rates"), cohort = 1950), 
     type = "l", log = "y", xlab = "age", ylab = "Mortality rate", 
     main = "Mortality rates for the 1950 cohort", 
     xlim = c(55,89), ylim = c(0.005, 0.12))
matlines(62:89, mSim, lty = 2)

amvillegas/StMoMo documentation built on Nov. 7, 2019, 5:39 a.m.