downloadnLx: Extract Lx estimates from WPP2019. Mainly an util function...

View source: R/utils_downloads.R

downloadnLxR Documentation

Extract Lx estimates from WPP2019. Mainly an util function for other ones.

Description

We extract Lx from wpp2019, interpolated to exact dates. Different methods available. A vector of countries can handle, but with an unique sex. Row names are not indicative of countries.

Usage

downloadnLx(nLx, location, gender, nLxDatesIn, method = "linear")

Arguments

nLx

numeric. either NULL or a numeric vector of lifetable exposure. If it's the second then we just pass it back.

location

vector. UN Pop Div LocName or LocID

gender

character. "male", "female", or "both"

nLxDatesIn

numeric. Vector of three decimal dates produced by (or passed through) basepop_five()

method

character. Could be "linear", "exponential", or "power"

Value

numeric matrix of nLx with length(nLxDatesIn) and abridged ages in rows.

Examples

# life expectancy calculated from Lx downloaded from WPP19. Using names or codes.
Lxs_name <- downloadnLx(nLx=NULL, location = "Argentina",
                        gender = "both", nLxDatesIn = 1950:2030)
Lxs_code <- downloadnLx(nLx=NULL, location = "32",
                        gender = "both", nLxDatesIn = 1950:2030)
## Not run: 
plot(1950:2030, as.numeric(colSums(Lxs_name)), xlab = "Year", ylab="e0")
lines(1950:2030, as.numeric(colSums(Lxs_code)))

## End(Not run)
# life expectancy for different countries
Lxs_countries <- downloadnLx(nLx=NULL, location = c("Argentina","Brazil","Uruguay"),
gender = "both", nLxDatesIn = 1950:2025)
## Not run: 
plot(1950:2025, as.numeric(colSums(Lxs_countries[1:22,])), 
     t="l", xlab = "Year", ylab="e0", ylim = c(40,80))
lines(1950:2025, as.numeric(colSums(Lxs_countries[23:44,])), col=2)
lines(1950:2025, as.numeric(colSums(Lxs_countries[45:64,])), col=3)
legend("bottomright",c("Argentina","Brazil","Uruguay"),lty=1,col=1:3)

## End(Not run)

timriffe/DemoTools documentation built on Oct. 14, 2024, 12:53 p.m.