WH_2d | R Documentation |
Main package function to apply Whittaker-Henderson smoothing in a
bidimensional survival analysis framework. It takes as input a matrix of
observed events and a matrix of associated central exposure, both depending
on two covariates, and build a smooth version of the log-hazard rate.
Smoothing parameters may be supplied or automatically chosen according to a
specific criterion such as "REML"
(the default), "AIC"
, "BIC"
or
"GCV"
. Whittaker-Henderson may be applied in a full maximum likelihood
framework or an approximate gaussian framework. As Whittaker-Henderson
smoothing relies on full-rank smoothers, computation time and memory usage in
the bidimensional case may prove overwhelming and the function integrates a
rank-reduction procedure to avoid such issues.
WH_2d(
d,
ec,
lambda,
criterion,
method,
max_dim = 200,
p,
q = c(2, 2),
framework,
y,
wt,
quiet = FALSE,
...
)
d |
Matrix of observed events, whose rows and columns must be named. |
ec |
Matrix 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. |
lambda |
Smoothing parameter vector of size |
criterion |
Criterion to be used for the selection of the optimal
smoothing parameter. Default is |
method |
Method to be used to find the optimal smoothing parameter.
Default to |
max_dim |
Number of parameters to be kept in the optimization problem.
Default is |
p |
Optional vector of size |
q |
Order of penalization vector of size |
framework |
Default framework is |
y |
Optional matrix of observations whose rows and columns should be
named. Used only in the regression framework and if the |
wt |
Optional matrix of weights. As for the observation vector |
quiet |
Should messages and warnings be silenced ? Default to |
... |
Additional parameters passed to the smoothing function called. |
An object of class WH_2d
i.e. a list containing :
d
The inputed matrix of observed events (if supplied as input)
ec
The inputed matrix of central exposure (if supplied as input)
y
The observation matrix, either supplied or computed as y = log(d) - log(ec)
wt
The inputed matrix of weights, either supplied or set to d
y_hat
The matrix of values fitted using Whittaker-Henderson smoothing
std_y_hat
The matrix of standard deviations associated with the fit
res
The matrix of deviance residuals associated with the fit
edf_obs
The matrix of effective degrees of freedom associated with each observation
edf_par
The matrix 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 vector of smoothing parameters used.
p
The number of eigenvectors kept on each dimension if the rank reduction method
is used.
q
The supplied vector of orders for the penalization matrices.
keep_age <- which(rowSums(portfolio_LTC$ec) > 5e2)
keep_duration <- which(colSums(portfolio_LTC$ec) > 1e3)
d <- portfolio_LTC$d[keep_age, keep_duration]
ec <- portfolio_LTC$ec[keep_age, keep_duration]
y <- log(d / ec) # observation vector
y[d == 0] <- - 20
wt <- d
# Maximum likelihood
WH_2d(d, ec, lambda = c(1e2, 1e2))
WH_2d(d, ec) # performance iteration default method
WH_2d(d, ec, method = "outer") # slower but safer outer iteration method
WH_2d(d, ec, criterion = "GCV")
# alternative optimization criteria for smoothing parameter selection
# Regression
WH_2d(y = y, wt = wt, lambda = c(1e2, 1e2)) # regression framework is triggered when y is supplied
WH_2d(d, ec, framework = "reg", lambda = c(1e2, 1e2))
# setting framework = "reg" forces computation of y from d and ec
# Rank reduction
keep_age <- which(rowSums(portfolio_LTC$ec) > 1e2)
keep_duration <- which(colSums(portfolio_LTC$ec) > 1e2)
d <- portfolio_LTC$d[keep_age, keep_duration]
ec <- portfolio_LTC$ec[keep_age, keep_duration]
prod(dim(d)) # problem dimension is 627 !
WH_2d(d, ec)
# rank-reduction is used to find an approximate solution using 200 parameters
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.