smooth_age_5_zigzag_min: Objective function to minimize Feeney's zigzag method...

View source: R/ZIGZAG.R

smooth_age_5_zigzag_minR Documentation

Objective function to minimize Feeney's zigzag method residual

Description

This function is auxiliary to smooth_age_5_zigzag_inner(), see ?smooth_age_5_zigzag_inner for a description.

Usage

smooth_age_5_zigzag_min(Value, Age, ageMin = 40, ageMax = 80, p)

Arguments

Value

numeric vector of (presumably) counts in 5-year age groups.

Age

integer vector of age group lower bounds.

ageMin

integer. Lower age bound to adjust values.

ageMax

integer. Upper age bound to adjust values.

p

numeric vector of adjustment parameters.

Details

This function is not intended to be used at the top level, but just in case, make sure that ageMax = ageMin + 10 * length(p). Age groups >= ageMin AND <= ageMin must be in 5-year age groups. This function does no checks.

Value

positive residual to minimize.

References

Feeney, G. 2013 "Removing "Zigzag" from Age Data," http://demographer.com/white-papers/2013-removing-zigzag-from-age-data/

Examples

Age <- c(0,1,seq(5,90,by=5))
smooth_age_5_zigzag_min(dth5_zigzag,Age,ageMin=40,ageMax = 80,p=rep(.05,4))
# it's used like this in zigzag()
(p <- optim(
		rep(.05,4),
		smooth_age_5_zigzag_min,
		Value = dth5_zigzag,
		Age = Age,
		ageMin = 40,
		ageMax = 80)$par)
Smoothed <- smooth_age_5_zigzag_p(dth5_zigzag,Age,40,80,p)
# de facto unit test:
# check result using results frozen in Feeney spreadsheet
# after fixing probable cell range 'error'
p.feeney <- c(0.0235802695087692,0.0724286618207911,
		      0.0242327829742267,0.0883411499065237)
ans      <- 106.1147411629
stopifnot(abs(smooth_age_5_zigzag_min(dth5_zigzag, Age, 40,80,p.feeney) - ans) < 1e-6)

timriffe/DemoTools documentation built on Jan. 28, 2024, 5:13 a.m.