compute.loess | R Documentation |
Functions for computing residuals from the observed life expectancy and MCMC estimation, and fitting a local polynomial regression.
compute.residuals(sim.dir, burnin = 1000)
compute.loess(sim.dir = NULL, burnin = 1000, residuals = NULL)
sim.dir |
Directory with the MCMC estimation. In |
burnin |
Number of (unthinned) iterations to be discarded. In |
residuals |
Residuals can be computed outside of the |
The Bayesian hierarchical model for life expectancy uses a lowess curve as a multiplier of the variance. The dataset is stored in the package as the loess_sd
dataset. These functions can be used to re-compute this loess_sd
dataset. In such a case, the simulation should be run with the argument constant.variance = TRUE
(in run.e0.mcmc
).
The residuals are computed for each country as the absolute differences between the observed life expectancy increases and the mean of the estimated double logistic function at the corresponding life expectancy level.
compute.residuals
returns a data frame with columns ‘x’ (life expectancy levels) and ‘y’ (absolute residuals).
compute.loess
also returns a data frame with columns ‘x’ and ‘y’, where ‘x’ is the same as before (with added a minimum and maximum) and ‘y’ is the local polynomial fit with constant tails.
Hana Sevcikova
run.e0.mcmc
sim.dir <- file.path(find.package("bayesLife"), "ex-data", "bayesLife.output")
resid <- compute.residuals(sim.dir, burnin = 30)
lws <- compute.loess(residuals = resid)
# plot residuals and loess
plot(resid$x, resid$y, ylim = c(0, 4))
lines(lws$x, lws$y, col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.