plot.DLM {BayesMortalityPlus}R Documentation

DLM: Plot the life table

Description

Function that returns a log-scale ggplot of the DLM and ClosedDLM objects returned by dlm() and dlm_close() functions.

Usage

## S3 method for class 'DLM'
plot(
  x,
  plotIC = TRUE,
  plotData = TRUE,
  labels = NULL,
  colors = NULL,
  linetype = NULL,
  prob = 0.95,
  age = NULL,
  ...
)

Arguments

x

Object of the class DLM or ClosedDLM returned by the dlm() or dlm_close() functions.

plotIC

Logical. If 'TRUE' (default), shows the predictive intervals.

plotData

Logical. If 'TRUE' (default), shows crude rate (black dots).

labels

Vector with the name of the curve label. (Optional).

colors

Vector with the color of the curve. (Optional).

linetype

Vector with the line type of the curve. (Optional).

prob

Coverage probability of the predictive intervals. Default is '0.95'.

age

Vector with the ages to plot the life table.

...

Other arguments.

Value

A 'ggplot' object with fitted life table.

See Also

plot.HP(), plot.BLC() and plot.PredBLC() for HP, BLC or PredBLC methods.

plot.list() to the list method, adding multiple objects in one single plot.

plot_chain() to plot the chains generated by the MCMC algorithms for the HP and DLM objects.

Examples

## Selecting the log mortality rate of the 1990 male population ranging from 0 to 100 years old
USA1990 = USA[USA$Year == 1990,]
x = 0:100
Ex = USA1990$Ex.Male[x+1]
Dx = USA1990$Dx.Male[x+1]
y = log(Dx/Ex)

## Fitting DLM
fit = dlm(y, ages = 0:100, M = 100)

## Plotting the life tables:
plot(fit)

## Now we are starting from 20 years

fit2 = dlm(y[21:101], Ft = 1, Gt = 1, ages = 20:100, M = 100)

plot(fit2, plotIC = FALSE)

## To plot multiples life tables see ?plot.list
plot(list(fit, fit2), age = 20:100,
     plotData = FALSE,
     colors = c("red", "blue"),
     labels = c("1", "2"))




[Package BayesMortalityPlus version 0.2.3 Index]