For a given set of age groups to fit against, and a given stable growth rate, $r$, what is the error implied given the current $r$ and stationary standard?

OPAG_r_min(r, Age_fit, Pop_fit, AgeInt_fit, Lx1, Age_Lx1)

## Arguments

r given stable growth rate integer vector of lower bounds for age groups of Pop_fit numeric vector of at least two population counts to use for fitting integer vector of widths of age groups of Pop_fit numeric vector of stable population standard by single ages integer vector of lower bounds for age groups of Lx1

## Value

numeric. A residual that you're presumably trying to minimize.

## Details

This is a utility function for OPAG(), which needs to optimize $r$ for a given population vector and stationary standard.

## Examples

# Make up some population data to fit to:
Pop_fit    <- c(85000,37000)
Age_fit    <- c(70,80)
AgeInt_fit <- c(10,10)
#> Downloading nLx data for Spain, years 1971, gender female# graduate(nLx, Age_nLx, method = method, constrain = TRUE)
Ageab    <- names2age(nLx)
Lx1 <- graduate(c(nLx), Ageab, method = "mono", constrain = TRUE)
Age_Lx1 <- 0:100
r          <- .01

OPAG_r_min(r,
Pop_fit = Pop_fit,
Age_fit = Age_fit,
AgeInt_fit = AgeInt_fit,
Lx1 = Lx1,
Age_Lx1 = Age_Lx1)
#>  0.03025071
(r_opt <- optimize(OPAG_r_min,
Pop_fit = Pop_fit,
Age_fit = Age_fit,
AgeInt_fit = AgeInt_fit,
Lx1 = Lx1,
Age_Lx1 = Age_Lx1,
interval = c(-0.05,.05))\$min)
#>  0.002199804