Main package function to apply Whittaker-Henderson smoothing in a
one-dimensional survival analysis framework. It takes as input a vector of
observed events and a vector of associated central exposure, both depending
on a single covariate, and build a smooth version of the log-hazard rate.
Smoothing parameters may be supplied or automatically chosen according to an
adequate criterion such as "REML"
(the default), "AIC"
, "BIC"
or
"GCV"
. Whittaker-Henderson may be applied in a full maximum likelihood
framework (the default) or an approximate gaussian framework (the original).
WH_1d(
d,
ec,
lambda,
criterion,
method,
q = 2,
framework,
y,
wt,
quiet = FALSE,
...
)
An object of class WH_1d
i.e. a list containing :
d
The inputed vector of observed events (if supplied as input)
ec
The inputed vector of central exposure (if supplied as input)
y
The observation vector, either supplied or computed as y = log(d) - log(ec)
wt
The inputed vector of weights, either supplied or computed as d
y_hat
The vector of values fitted using Whittaker-Henderson smoothing
std_y_hat
The vector of standard deviation associated with the fit
res
The vector of deviance residuals associated with the fit
edf_obs
The vector of effective degrees of freedom associated with each observation
edf_par
The vector of effective degrees of freedom associated with each eigenvector
diagnosis
A data.frame with one line containing the sum of effective degrees of freedom
for the model, the deviance of the fit as well as the AIC, BIC, GCV and
REML criteria
Psi
The variance-covariance matrix associated with the fit, which is required
for the extrapolation step.
lambda
The smoothing parameter used.
p
The number of eigenvectors kept on each dimension if the rank reduction method
is used (it should not in the one-dimensional case).
q
The supplied order for the penalization matrix.
Vector of observed events, should have named elements.
Vector of central exposure. The central exposure corresponds to the sum of the exposure duration over the insured population. An individual experiencing an event of interest during the year will no longer be exposed afterward and the exposure should be computed accordingly.
Smoothing parameter. If missing, an optimization procedure will
be used to find the optimal smoothing parameter. If supplied, no optimal
smoothing parameter search will take place unless the method
argument is
also supplied, in which case lambda
will be used as the starting
parameter for the optimization procedure.
Criterion to be used for the selection of the optimal
smoothing parameter. Default is "REML"
which stands for restricted
maximum likelihood. Other options include "AIC"
, "BIC"
and "GCV"
.
Method to be used to find the optimal smoothing parameter.
Default to "fixed_lambda"
if lambda
is supplied, meaning no
optimization is performed. Otherwise, default to the most reliable
"outer"
method based on the optimize
function from package stats
.
Order of penalization. Polynoms of degrees q - 1
are considered
completely smooth and are therefore unpenalized. Should be left to the
default of 2
for most practical applications.
Default framework is "ml"
which stands for maximum
likelihood unless the y
argument is also provided, in which case an
"reg"
or (approximate) regression framework is used.
Optional vector of observations whose elements should be named. Used
only in the regression framework and if the d
and ec
arguments are
missing (otherwise y
is automatically computed from d
and ec
). May be
useful when using Whittaker-Henderson smoothing outside of the survival
analysis framework.
Optional vector of weights. As for the observation vector y
, used
only in the regression framework and if the d
and ec
arguments are
missing (otherwise wt
is automatically set to d
). May be useful when
using Whittaker-Henderson smoothing outside of the survival analysis
framework.
Should messages and warnings be silenced ? Default to FALSE
,
may be set to TRUE
is the function is called repeatedly.
Additional parameters passed to the smoothing function called.
d <- portfolio_mort$d
ec <- portfolio_mort$ec
y <- log(d / ec)
y[d == 0] <- - 20
wt <- d
# Maximum likelihood
WH_1d(d, ec, lambda = 1e2)
WH_1d(d, ec) # default outer iteration method based on the optimize function
WH_1d(d, ec, criterion = "GCV")
# alternative optimization criterion for smoothing parameter selection
# Regression
WH_1d(y = y, wt = wt, lambda = 1e2) # regression framework is default when y is supplied
WH_1d(d, ec, framework = "reg", lambda = 1e2)
# setting framework = "reg" forces computation of y from d and ec
Run the code above in your browser using DataLab