Learn R Programming

ROMIplot (version 1.0)

create.Lexis.matrix: Creates a Lexis surface matrix.

Description

Creates a matrix (age by year) based on data formatted in the Human Mortality Database format.

Usage

create.Lexis.matrix(HMD.dataset, Sex = "Female", minage = 50, maxage = 100, minyear = 1950, maxyear = 2011)

Arguments

HMD.dataset
A dataset as formatted in the Human Mortality Database, i.e. a data frame with the columns "Year", "Age", "Female", "Male", "Total"
Sex
For which sex should the matrix be created? Default setting is "Female". Other options are "Male" and "Total".
minage
HMD data cover ages 0 to 100. Please select here a value for the lower bound to be included. Default is 50.
maxage
HMD data cover ages 0 to 100. Please select here a value for the upper bound to be included. Default is 100.
minyear
Please select the first year to be included in the matrix. Default is 1950.
maxyear
Please select the last year to be included in the matrix. Default is 2011.

Value

A matrix with the dimensions: length(minage:maxage) x length(minyear:maxyear) Rows represent ages, columns represent years.

Details

It is expected that age is an integer.

Examples

Run this code

theyears <- 1900:2012
theages <- 0:110
n <- length(theyears) * length(theages)

# 'Simulating' a data frame in the HMD format
HMD.formatted.data <- data.frame(Year=sort(rep(theyears, length(theages))),
                                 Age = rep(theages, length(theyears)),
                                 Female = runif(n=n),
                                 Male = runif(n=n),
                                 Total = runif(n=n))

a.Lexis.matrix <- create.Lexis.matrix(HMD.dataset=HMD.formatted.data,
                                      Sex="Total", minage=30, maxage=105,
                                      minyear=1905, maxyear=2010)

Run the code above in your browser using DataLab