Title: | Smoothing of Two-Dimensional Demographic Data, Optionally Taking into Account Period and Cohort Effects |
---|---|
Description: | The implemented method uses for smoothing bivariate thin plate splines, bivariate lasso-type regularization, and allows for both period and cohort effects. Thus the mortality rates are modelled as the sum of four components: a smooth bivariate function of age and time, smooth one-dimensional cohort effects, smooth one-dimensional period effects and random errors. |
Authors: | Alexander Dokumentov, Rob J Hyndman |
Maintainer: | Alexander Dokumentov <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3 |
Built: | 2024-10-13 06:52:58 UTC |
Source: | https://github.com/cran/smoothAPC |
If period and cohort effects are taken into account (effects = TRUE) the method uses all available years and diagonals for estimation of the period and cohort effects.
autoSmoothAPC(data, effects = TRUE, cornerLength = 7, affdDiagonals = NULL, affdYears = NULL, lower = head(c(0.01, 0.01, 0.01, 2, 0.001, 2, 0.001), 3 + effects * 4), upper = head(c(1.2, 1.8, 1.2, 12, 0.4, 12, 0.4), 3 + effects * 4), init = head(c(0.1, 0.1, 0.2, 4, 0.001, 4, 0.001), 3 + effects * 4), reltol = 0.001, parameters = NULL, trace = F, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
autoSmoothAPC(data, effects = TRUE, cornerLength = 7, affdDiagonals = NULL, affdYears = NULL, lower = head(c(0.01, 0.01, 0.01, 2, 0.001, 2, 0.001), 3 + effects * 4), upper = head(c(1.2, 1.8, 1.2, 12, 0.4, 12, 0.4), 3 + effects * 4), init = head(c(0.1, 0.1, 0.2, 4, 0.001, 4, 0.001), 3 + effects * 4), reltol = 0.001, parameters = NULL, trace = F, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
data |
Demographic data (log mortality) presented as a matrix. Row numbers represent ages and column numbers represet time. |
effects |
Controls if the cohort and period effects are taken into account. |
cornerLength |
Sets the smallest length of a diagonal to be considered for cohort effects. |
affdDiagonals |
Diagonals to be used for cohort effects. The first diagonal is at the bottom left corner of the data matrix (maximal age and minimal time in the data matrix). |
affdYears |
Years to be used for period effects. |
lower |
Lowest possible values for the optimization procedure. |
upper |
Highest possible values for the optimization procedure. |
init |
Initial values for the optimization procedure. |
reltol |
Relative tolerance parameter to be supplied to |
parameters |
Optional model parameters. If not provided, they are estimated. |
trace |
Controls if tracing is on. |
control |
The control data passed directly to |
weights |
Define how much every observation effect the resulting smooth surface.
The parameter must have same dimentions as |
A list of four components: smooth surface, period effects, cohort effects and parameters used for smoothing (passed as a parameter or estimated).
Alexander Dokumentov
http://robjhyndman.com/publications/mortality-smoothing/
smoothAPC
and signifAutoSmoothAPC
. The latter might give slightly better performance.
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot(m) sm <- autoSmoothAPC(m) plot(sm) plot(sm, "period") plot(sm, "cohort")
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot(m) sm <- autoSmoothAPC(m) plot(sm) plot(sm, "period") plot(sm, "cohort")
Presents matrix as a heatmap
## S3 method for class 'matrix' plot(x, labs = c("X", "Y"), color.palette = c("default", "special"), main = "", ...)
## S3 method for class 'matrix' plot(x, labs = c("X", "Y"), color.palette = c("default", "special"), main = "", ...)
x |
Matrix to plot. |
labs |
Vector of labels for X and Y axes. |
color.palette |
Character string |
main |
Title for the plot. |
... |
Other parameters. They are currently ignored. |
Alexander Dokumentov
plot(matrix(rnorm(100),10,10), main = "Noise") plot(matrix(1:100,10,10), c("Dimension 1", "Dimension 2"), main = "Value") library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot(m) plot(m, color.palette = "special") plot(m, color.palette = rainbow)
plot(matrix(rnorm(100),10,10), main = "Noise") plot(matrix(1:100,10,10), c("Dimension 1", "Dimension 2"), main = "Value") library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot(m) plot(m, color.palette = "special") plot(m, color.palette = rainbow)
Presents demographic data as a heatmap
## S3 method for class 'smAPC' plot(x, component = c("all", "surface", "period", "cohort", "residuals", "original"), labs = c("Age", "Time"), color.palette = c("default", "special"), main = "", ...)
## S3 method for class 'smAPC' plot(x, component = c("all", "surface", "period", "cohort", "residuals", "original"), labs = c("Age", "Time"), color.palette = c("default", "special"), main = "", ...)
x |
Result of smoothing (object of class |
component |
"smooth", "period", "cohort", "residuals" or "original". |
labs |
Vector of labels for X and Y axes. |
color.palette |
Character string |
main |
Title for the plot. |
... |
Other parameters. They are currently ignored. |
Alexander Dokumentov
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- autoSmoothAPC(m) plot(sm) plot(sm, "surface") plot(sm, "cohort") plot(sm, "period") plot(sm, "residuals") plot(sm, "original", main = "Original data")
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- autoSmoothAPC(m) plot(sm) plot(sm, "surface") plot(sm, "cohort") plot(sm, "period") plot(sm, "residuals") plot(sm, "original", main = "Original data")
Presents data as a 3D surface
plot3d(x, ...)
plot3d(x, ...)
x |
Data to plot. |
... |
Other parameters. |
Presents matrix as a 3D surface
## S3 method for class 'matrix' plot3d(x, labs = c("X", "Y", "Z"), color.palette = c("default", "special"), ...)
## S3 method for class 'matrix' plot3d(x, labs = c("X", "Y", "Z"), color.palette = c("default", "special"), ...)
x |
Matrix to plot. |
labs |
Vector of labels for X, Y and Z axes. |
color.palette |
Character string |
... |
Other parameters. They are currently ignored. |
Alexander Dokumentov
plot3d(matrix(rnorm(100),10,10)) plot3d(matrix(1:100,10,10), c("Dimension 1", "Dimension 2", "Value")) library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot3d(m) plot3d(m, color.palette = "special") plot3d(m, color.palette = rainbow)
plot3d(matrix(rnorm(100),10,10)) plot3d(matrix(1:100,10,10), c("Dimension 1", "Dimension 2", "Value")) library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) plot3d(m) plot3d(m, color.palette = "special") plot3d(m, color.palette = rainbow)
Presents demographic data as a 3D surface
## S3 method for class 'smAPC' plot3d(x, component = c("all", "surface", "period", "cohort", "residuals", "original"), labs = c("Age", "Time", NA), color.palette = c("default", "special"), ...)
## S3 method for class 'smAPC' plot3d(x, component = c("all", "surface", "period", "cohort", "residuals", "original"), labs = c("Age", "Time", NA), color.palette = c("default", "special"), ...)
x |
Result of smoothing (object of class |
component |
"smooth", "period", "cohort", "residuals" or "original". |
labs |
Vector of labels for X, Y and Z axes. |
color.palette |
Character string |
... |
Other parameters. They are currently ignored. |
Alexander Dokumentov
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- autoSmoothAPC(m) plot3d(sm) plot3d(sm, "surface", color.palette = "special") plot3d(sm, "cohort") plot3d(sm, "period") plot3d(sm, "residuals") plot3d(sm, "original", color.palette = rainbow)
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- autoSmoothAPC(m) plot3d(sm) plot3d(sm, "surface", color.palette = "special") plot3d(sm, "cohort") plot3d(sm, "period") plot3d(sm, "residuals") plot3d(sm, "original", color.palette = rainbow)
It is a heuristic procedure which tries to figure out positions of
period and cohort effects in the data. It also uses a few steps to estimate
model's parameters. The procedure is supposed to outperform autoSmoothAPC
slightly.
signifAutoSmoothAPC(data, p.value = 0.05, cornerLength = 7, lower = c(0.01, 0.01, 0.01, 1, 0.001, 1, 0.001), upper = c(1.2, 1.8, 1.2, 12, 0.4, 12, 0.4), init = c(0.1, 0.1, 0.2, 4, 0.001, 4, 0.001), reltol = 0.001, trace = F, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
signifAutoSmoothAPC(data, p.value = 0.05, cornerLength = 7, lower = c(0.01, 0.01, 0.01, 1, 0.001, 1, 0.001), upper = c(1.2, 1.8, 1.2, 12, 0.4, 12, 0.4), init = c(0.1, 0.1, 0.2, 4, 0.001, 4, 0.001), reltol = 0.001, trace = F, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
data |
Demographic data (log mortality) presented as a matrix. Row numbers represent ages and column numbers represet time. |
p.value |
P-value used to test the period and the cohort effects for significance. The lower the value the fewer diagonals and years will be used to find cohort and period effects. |
cornerLength |
Minimal length of a diagonal to be considered for cohort effects. |
lower |
Lowest possible values for the optimization procedure. |
upper |
Highest possible values for the optimization procedure. |
init |
Initial values for the optimization procedure. |
reltol |
Relative tolerance parameter to be supplied to |
trace |
Controls if tracing is on. |
control |
The control data passed directly to |
weights |
Define how much every observation effect the resulting smooth surface.
The parameter must have same dimentions as |
A list of six components: smooth surface, period effects, cohort effects, parameters used for smoothing, diagonals used for cohort effects and years used for period effects.
Alexander Dokumentov
http://robjhyndman.com/publications/mortality-smoothing/
library(demography) m <- log(fr.mort$rate$female[1:30, 120:139]) plot(m) sm <- signifAutoSmoothAPC(m) plot(sm) plot(sm, "surface") plot(sm, "period") plot(sm, "cohort")
library(demography) m <- log(fr.mort$rate$female[1:30, 120:139]) plot(m) sm <- signifAutoSmoothAPC(m) plot(sm) plot(sm, "surface") plot(sm, "period") plot(sm, "cohort")
Smooths demographic data optionally taking into account period and cohort effects
smoothAPC(data, lambda = 1, lambdaaa = 1, lambdayy = 1, lambdaay = 1, lambdaYearsEffect = 5, thetaYearsEffect = 0.1 * lambda, lambdaCohortEffect = 5, thetaCohortEffect = 0.1 * lambda, cornerLength = 7, effects = TRUE, affdDiagonals = NULL, affdYears = NULL, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
smoothAPC(data, lambda = 1, lambdaaa = 1, lambdayy = 1, lambdaay = 1, lambdaYearsEffect = 5, thetaYearsEffect = 0.1 * lambda, lambdaCohortEffect = 5, thetaCohortEffect = 0.1 * lambda, cornerLength = 7, effects = TRUE, affdDiagonals = NULL, affdYears = NULL, control = list(nnzlmax = 1e+06, nsubmax = 2e+06, tmpmax = 2e+05), weights = NULL)
data |
Demographic data (log mortality) presented as a matrix. Row numbers represent ages and column numbers represet time. |
lambda |
Controls "general flexibility" of the smooth surface. |
lambdaaa |
Controls "flexibility" of the smooth surface in age direction (first dimension). |
lambdayy |
Controls "flexibility" of the smooth surface in years direction (second dimension). |
lambdaay |
Controls "flexibility" of the smooth surface in age and years directions. |
lambdaYearsEffect |
Controls "flexibility" of the period effects. |
thetaYearsEffect |
Reduces the likelihood of period effects. |
lambdaCohortEffect |
Controls "flexibility" of the cohort effects. |
thetaCohortEffect |
Reduces the likelihood of cohort effects. |
cornerLength |
Sets the smallest length of a diagonal to be considered for cohort effects. |
effects |
Controls if the cohort and period effects are taken into account. |
affdDiagonals |
Diagonals to be used for cohort effects. |
affdYears |
Years to be used for period effects. |
control |
Control data passed directly to |
weights |
Define how much every observation effect the resulting smooth surface.
The parameter must have same dimentions as |
List of three components: smooth surface, period effects, cohort effects.
Alexander Dokumentov
http://robjhyndman.com/publications/mortality-smoothing/
autoSmoothAPC
, signifAutoSmoothAPC
.
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- smoothAPC(m, lambdaaa = 0.2, lambdayy = 0.1, lambdaay = 0.4, effects = FALSE) plot(sm, "original") plot(sm)
library(demography) m <- log(fr.mort$rate$female[1:30, 150:160]) sm <- smoothAPC(m, lambdaaa = 0.2, lambdayy = 0.1, lambdaay = 0.4, effects = FALSE) plot(sm, "original") plot(sm)