OPAG_r_min: calculates residual for optimizing growth rate r for OPAG...

View source: R/OPAG.R

OPAG_r_minR Documentation

calculates residual for optimizing growth rate r for OPAG family

Description

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?

Usage

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

Arguments

r

given stable growth rate

Age_fit

integer vector of lower bounds for age groups of Pop_fit

Pop_fit

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

AgeInt_fit

integer vector of widths of age groups of Pop_fit

Lx1

numeric vector of stable population standard by single ages

Age_Lx1

integer vector of lower bounds for age groups of Lx1

Details

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

Value

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

Examples

# 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)
# 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)

(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)


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