graduate_mono_closeout: blend the Sprague upper boundary age estimates into monotonic...

View source: R/graduate.R

graduate_mono_closeoutR Documentation

blend the Sprague upper boundary age estimates into monotonic spline estimates

Description

A simple monotonic spline on the cumulative sum of population counts may return more convincing single age count estimates than the Sprague or other splitting methods. This function blends the given single age population estimates starting at pivotAge.

Usage

graduate_mono_closeout(
  Value,
  Age,
  pops,
  pivotAge = 90,
  splitfun = graduate_sprague,
  OAG = TRUE,
  ...
)

Arguments

Value

numeric vector, presumably counts in grouped ages

Age

integer vector, lower bounds of age groups

pops

optional numeric vector of single age population counts derived from Value.

pivotAge

integer (default 90). Age at which to switch to spline-based estimates.

splitfun

optional. The function used to create pops. Default graduate_sprague. Could also be graduate_grabill, or any other function that similarly transforms.

OAG

logical (default FALSE). Would we like to re-impute the last element of Value as the open age group?

...

arguments to be optionally passed to splitfun().

Details

The pivotAge must be at least 10 years below the maximum age detected from rownames(popmat), but not lower than 75. In the exact pivotAge, we may either take the Sprague estimates or the spline estimates, depending on which is larger, then the single-age estimates for this 5-year age group are rescaled to sum to the original total in Value. Higher ages are taken from the spline-based age splits. The spline results are derive from the "hyman" method of splinefun() on the cumulative sum of the original age grouped data. One could use this function to perform the same closeout to Grabill estimates, if these are given via the pops argument. See examples. Note that the Grabill split method mixed with this closeout will not necessarily preserve the annual totals, and this function performs to rescaling. The open age group is preserved (and must be included in Value).

Value

numeric matrix of age by year estimates of single-age counts.

Examples

a5 <- as.integer(rownames(pop5_mat))
popvec               <- pop5_mat[,1]
closed.out           <- graduate_mono_closeout(Value = popvec, Age = a5, OAG = TRUE)
sum(closed.out) - sum(popvec)
graduate_mono_closeout(Value = popvec, pivotAge = 85, Age = a5, OAG = TRUE)
# giving a different single-age split to close out this way:
popg                 <- graduate_grabill(Value = popvec, Age = a5, OAG = TRUE)
grabill.closed.out   <- graduate_mono_closeout(Value = popvec, Age = a5, pops = popg)
# totals not necessarily preserved if mixed w Grabill
# I wouldn't recommend a rescale of the total, since the
# only part we mess with here is the old age section. Ergo,
# one may wish to instead rescale results colSums() of
# popg at age pivotAge and higher.
sum(grabill.closed.out) - sum(popvec)
# also works on an age-labeled vector of data
closed.vec           <- graduate_mono_closeout(popvec, Age = a5, OAG = TRUE)
# let's compare this one with sprague()
simple.vec           <- graduate_sprague(popvec, Age = a5, OAG = TRUE)
# and with a simple monotonic spline
mono.vec             <- graduate_mono(popvec, Age = a5, OAG = TRUE)
## Not run: 
plot(85:100,simple.vec[86:101], type = 'l',
 main = "In this case graduate_sprague() is the smoothest")
lines(85:100,closed.vec[86:101], col = "red", lwd = 2)
lines(85:100,mono.vec[86:101], col = "blue", lty = 2)
legend("topright",lty=c(1,2,2), col = c("black","red","blue"),lwd = c(1,2,1),
		legend = c("graduate_sprague()","monoCloseout()", "graduate_mono()"))

## End(Not run)

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