smooth_spline {vital} | R Documentation |
Functions to smooth demographic data
Description
These smoothing functions allow smoothing of a variable in a vital object.
The vital object is returned along with some additional columns containing
information about the smoothed variable: usually .smooth
containing the
smoothed values, and .smooth_se
containing the corresponding standard errors.
Usage
smooth_spline(.data, .var, age_spacing = 1, k = -1)
smooth_mortality(.data, .var, age_spacing = 1, b = 65, power = 0.4, k = 30)
smooth_fertility(.data, .var, age_spacing = 1, lambda = 1e-10)
smooth_loess(.data, .var, age_spacing = 1, span = 0.2)
Arguments
.data |
A vital object |
.var |
name of variable to smooth |
age_spacing |
Spacing between ages for smoothed vital. Default is 1. |
k |
Number of knots to use for penalized regression spline estimate. |
b |
Lower age for monotonicity. Above this, the smooth curve is assumed to be monotonically increasing. |
power |
Power transformation for age variable before smoothing. Default is 0.4 (for mortality data). |
lambda |
Penalty for constrained regression spline. |
span |
Span for loess smooth. |
Details
smooth_mortality()
use penalized regression splines applied to log mortality
with a monotonicity constraint above age b
. The methodology is based on Wood (1994).
smooth_fertility()
uses weighted regression B-splines with a concavity constraint,
based on He and Ng (1999). The function smooth_loess()
uses locally quadratic
regression, while smooth_spline()
uses penalized regression splines.
Value
vital with added columns containing smoothed values and their standard errors
Author(s)
Rob J Hyndman
References
Hyndman, R.J., and Ullah, S. (2007) Robust forecasting of mortality and fertility rates: a functional data approach. Computational Statistics & Data Analysis, 51, 4942-4956. https://robjhyndman.com/publications/funcfor/
Examples
library(dplyr)
aus_mortality |>
filter(State == "Victoria", Sex == "female", Year > 2000) |>
smooth_mortality(Mortality)
aus_fertility |>
filter(Year > 2000) |>
smooth_fertility(Fertility)