knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

Society Of Actuaries mortable web-crawler

The SOAmort is a R package that makes web crawling of a website call SOA mort. It has functions to obtain the mortality table data hosted on the website mort.soa.org.

Install package

devtools::install_github("issactoast/SOAmort")

Load package

library(SOAmort)

The package consists of three functions:

The mort.soa page provide the search options for the various tables using search parameters such as Usage, Nation, Table layout etc. The first two function will used for accessing the search result of the website.

Search table using makeSearchInfo and getTableInfo

We will make a body to make a search request parameter which can be fed to the getTableInfo function. For example, if we want to search the table for USA's Annuitant Mortality select table, the search parameter will be the following:

myrequest <- makeSearchInfo(
    tableUsage = "Annuitant Mortality",
    nation = "United States of America",
    tableType = "Select")

After make the request parameter, we can feed this to the function getTableInfo as follows:

result <- getTableInfo(myrequest)

result variable is a list which contains the infomation of the search result from the website.

# Table numbers which satisfies to the request
result$TableIdentity

# Table Name/ Description
result$TableName

# Table Usage
result$ContentType

We can see there are 7 tables in the result.

Access to the tables using table number

The getTable function allows you to access the actual table using the table number. For example, you can obtain the fist table, whose number is 856, in the result variable as follows:

result <- SOAmort::getTable(856)

The package is using httr package to crawling, it will keep trying to catch the table utill it reach the maximum try or success to grab the table information.

length(result)

Result shows that there are two table in the 856 table. To see the information about the table you can use attributes function.

names(attributes(result[[1]]))

To see the difference between the two table, let us check the table description.

attributes(result[[1]])$`Table Description`
attributes(result[[2]])$`Table Description`

It says the second table is the Railway Disabled Annuitants Mortality Ultimate Table whose minimum age 38 and the maximum age 95.

RRBultmort <- result[[2]]
dim(RRBultmort)
min(RRBultmort$age)
max(RRBultmort$age)
head(RRBultmort)
plot(RRBultmort$age, RRBultmort$`Column 1`,
     main = "The Railway Disabled Annuitants Mortality rate",
     xlab = "age",
     ylab = "mortality rate")

Give me your feedback

If you are having any issue and have an idea about the package, please make an issue in the github repo.



issactoast/r4actuaries documentation built on Dec. 3, 2020, 10:49 p.m.