compute.loess: Computing Residuals and Fitting Local Polynomial Regression

View source: R/functions.R

compute.loessR Documentation

Computing Residuals and Fitting Local Polynomial Regression

Description

Functions for computing residuals from the observed life expectancy and MCMC estimation, and fitting a local polynomial regression.

Usage

compute.residuals(sim.dir, burnin = 1000)

compute.loess(sim.dir = NULL, burnin = 1000, residuals = NULL)

Arguments

sim.dir

Directory with the MCMC estimation. In compute.loess, it is only used if residuals is not given.

burnin

Number of (unthinned) iterations to be discarded. In compute.loess, it is only used if residuals is not given.

residuals

Residuals can be computed outside of the compute.loess function and passed as the residuals argument. If not given, the compute.loess function calls compute.residuals internally, in which case sim.dir must be given.

Details

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.

Value

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.

Author(s)

Hana Sevcikova

See Also

run.e0.mcmc

Examples

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")

bayesLife documentation built on Sept. 16, 2023, 9:07 a.m.