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)

r | given stable growth rate |
---|---|

Age_fit | integer vector of lower bounds for age groups of |

Pop_fit | numeric vector of at least two population counts to use for fitting |

AgeInt_fit | integer vector of widths of age groups of |

Lx1 | numeric vector of stable population standard by single ages |

Age_Lx1 | integer vector of lower bounds for age groups of |

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

This is a utility function for `OPAG()`

, which needs to optimize $r$ for a
given population vector and stationary standard.

# Make up some population data to fit to: Pop_fit <- c(85000,37000) Age_fit <- c(70,80) AgeInt_fit <- c(10,10) nLx <- downloadnLx(NULL, "Spain","female",1971)#> 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)#> [1] 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)#> [1] 0.002199804