plot.HP {BayesMortalityPlus}R Documentation

HP: Plot the life table

Description

Function that returns a log-scale ggplot of HP and ClosedHP objects returned by the hp() and hp_close() functions.

Usage

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

Arguments

x

Object of the class HP or ClosedHP returned by hp() or hp_close() functions.

age

Vector with the ages to plot the life table.

Ex

Vector with the exposures of the selected ages. Its length must be equal to the age vector. This argument is only necessary when using poisson and binomial HP models.

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'.

...

Other arguments.

Value

A 'ggplot' object with fitted life table.

See Also

plot.DLM(), plot.BLC() and plot.PredBLC() for DLM, 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 exposure and the death count of the year 1990, ranging from 0 to 90 years old:
USA1990 = USA[USA$Year == 1990,]
x = 0:90
Ex = USA1990$Ex.Male[x+1]
Dx = USA1990$Dx.Male[x+1]

## Fitting the poisson and the lognormal model:
fit = hp(x = x, Ex = Ex, Dx = Dx, model = "poisson",
         M = 2000, bn = 1000, thin = 1)
fit2 = hp(x = x, Ex = Ex, Dx = Dx, model = "lognormal",
          M = 2000, bn = 1000, thin = 1)

## Plot the life tables:
plot(fit)
plot(fit2, age = 0:110, plotIC = TRUE)

## To plot multiples life tables see ?plot.list
plot(list(fit, fit2),
     age = 0:110, Ex = USA1990$Ex.Male,
     plotIC = FALSE, colors = c("red", "blue"),
     labels = c("Poisson", "Lognormal"))


[Package BayesMortalityPlus version 0.2.4 Index]