Last data update: 2014.03.03

R: Bayesian Melding posterior Heligman-Pollard parameter...
hpbayes.plotR Documentation

Bayesian Melding posterior Heligman-Pollard parameter distribution plot

Description

This function converts the posterior Heligman-Pollard parameter distribution resulting from a Bayesian Melding procedure to probabilities of death over a specified age range. In addition, this function also calculates and plots a CI over the specified age range. The user can also elect to plot the data (ndeath/nrisk) from which the model was estimated.

Usage

hpbayes.plot(..., nrisk = NULL, ndeath = NULL, age, hpp, 
yrange = c(0, 0.8), xrange = c(0, 85), log = FALSE, plotdata = FALSE, 
plotpost= TRUE, data.type="b", post.type="l", 
line.col=c("grey", "blue", "red", "dark green"), CI=95)

Arguments

...

Arguments to be passes to par

nrisk

A vector containing the number of persons at risk at age x

ndeath

A vector containing the number of deaths at age x

age

A vector containing the ages at which the probabilities of death will be calculated and plotted

hpp

A matrix containing the posterior distribution of Heligman-Pollard parameters resulting from the Bayesian Melding procedure

yrange

Same as ylim in plot()

xrange

Same as xlim in plot()

log

Logical. If TRUE the data will be converted and plotted on the log scale

plotdata

Logical. If TRUE the data (ndeath/nrisk) will be plotted as well.

plotpost

Logical. If TRUE the posterior output will be plotted.

data.type

Same as type in plot.

post.type

Same as type in plot. Defines the "type" for plotting the posterior age-specific probabilities of death

line.col

A vector of length four containing either numbers or strings describing the colors of the plot. In order, the vector elements control the color of the posterior output lines (defaults to "grey"), the color of the median line representing the median probability of death at each age (defaults to "blue"), the color of the two lines representing the upper and lower credible interval bounds (defaults to "red"), and the final element in this vector controls the color of the data points if they are plotted (defaults to "dark green").

CI

Defines the width of the credible interval if plotted (defaults to 95 percent). Setting CI=95 for example will plot two lines representing the upper and lower bounds of the confidence interval with the upper bound line representing the 97.5th percentile for each age and the lower bound representing the 2.5th percentile for each age.

Details

If plotdata is TRUE, the user will need to supply the persons at risk at each age x and the number of deaths at age x with the arguments nrisk and ndeath respectively.

Value

A plot depicting the posterior distribution of probabilities of death calculated from the posterior parameter distribution resulting from the Bayesian Melding procedure (see hp.bm.imis)

Note

Likely used to plot the H.final return from hp.bm.imis

References

Heligman, Larry and John H. Pollard. 1980 "The Age Pattern of Mortality." Journal of the Institute of Actuaries 107:49–80.

See Also

hp.nqx, hp.bm.imis

Examples




#load a prior, age, nrisk and ndeath#
data(HPprior)

result <- hp.bm.imis(prior=q0, K=10, age=age, nrisk=lx, ndeath=dx)
H.final <- result$H.final

hpbayes.plot(nrisk=lx, ndeath=dx, age=age, hpp=H.final, plotdata=TRUE)
hpbayes.plot(age=age, hpp=H.final)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(HPbayes)
Loading required package: MASS
Loading required package: mvtnorm
Loading required package: corpcor
Loading required package: numDeriv
Loading required package: boot
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HPbayes/hpbayes.plot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: hpbayes.plot
> ### Title: Bayesian Melding posterior Heligman-Pollard parameter
> ###   distribution plot
> ### Aliases: hpbayes.plot
> ### Keywords: misc
> 
> ### ** Examples
> 
> #load a prior, age, nrisk and ndeath#
> data(HPprior)
> 
> result <- hp.bm.imis(prior=q0, K=10, age=age, nrisk=lx, ndeath=dx)
  Low CI Median High CI
1  0.027  0.032   0.037
2  0.800  0.882   0.967
3  0.200  0.251   0.295
4  0.081  0.095   0.108
5  3.313  4.138   5.077
6 39.160 40.920  42.491
7  0.001  0.002   0.003
8  1.063  1.072   1.082
> H.final <- result$H.final
> 
> hpbayes.plot(nrisk=lx, ndeath=dx, age=age, hpp=H.final, plotdata=TRUE)
> hpbayes.plot(age=age, hpp=H.final)
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>