fit2ts {TwoTimeScales} | R Documentation |
Fit a smooth hazard model with two time scales
Description
fit2ts()
fits a smooth hazard model with two time scales.
Three methods are implemented for the search of the optimal smoothing
parameters (and therefore optimal model): a numerical optimization of the
AIC or BIC of the model, a search for the minimum AIC or BIC of the
model over a grid of log_10
values for the smoothing parameters, and a
solution that uses a sparse mixed model representation of the P-spline model to
estimate the smoothing parameters.
Construction of the B-splines bases and of the penalty matrix is
incorporated within the function. If a matrix of covariates is provided,
the function will estimate a model with covariates.
Usage
fit2ts(
data2ts = NULL,
Y = NULL,
R = NULL,
Z = NULL,
bins = NULL,
Bbases_spec = list(),
pord = 2,
optim_method = c("ucminf", "grid_search", "LMMsolver"),
optim_criterion = c("aic", "bic"),
lrho = c(0, 0),
Wprior = NULL,
ridge = 0,
control_algorithm = list(),
par_gridsearch = list()
)
Arguments
data2ts |
(optional) an object of class created by the function
|
Y |
A matrix (or 3d-array) of event counts of dimension nu by ns (or nu by ns by n). |
R |
A matrix (or 3d-array) of exposure times of dimension nu by ns (or nu by ns by n). |
Z |
(optional) A regression matrix of covariates values of dimensions n by p. |
bins |
a list with the specification for the bins. This is created by
the function |
Bbases_spec |
A list with the specification for the B-splines basis with the following elements:
|
pord |
The order of the penalty. Default is 2. |
optim_method |
The method to be used for optimization:
|
optim_criterion |
The criterion to be used for optimization:
|
lrho |
A vector of two elements if |
Wprior |
An optional matrix of a-priori weights. |
ridge |
A ridge penalty parameter: default is 0. This is useful when, in
some cases the algorithm shows convergence problems. In this case, set to a small
number, for example |
control_algorithm |
A list with optional values for the parameters of the iterative processes:
|
par_gridsearch |
A list of parameters for the grid_search:
|
Details
Some functions from the R-package LMMsolver
are used here.
We refer the interested readers to https://biometris.github.io/LMMsolver/
for more details on LMMsolver
and its usage.
Value
An object of class haz2ts
, or of class haz2tsLMM
.
For objects of class haz2ts
this is
-
optimal_model
A list with :-
Alpha
The matrix of estimated P-splines coefficients of dimensionc_u
byc_s
. -
Cov_alpha
The variance-covariance matrix of theAlpha
coefficients, of dimensionc_uc_s
byc_uc_s
. -
beta
The vector of length p of estimated covariates coefficients (if model with covariates). -
Cov_beta
The variance-covariance matrix of thebeta
coefficients, of dimensionp
byp
(if model with covariates). -
SE_beta
The vector of lengthp
of estimated Standard Errors for thebeta
coefficients (if model with covariates).. -
Eta
orEta0
The matrix of values of the (baseline) linear predictor (log-hazard) of dimensionn_u
byn_s
. -
H
The hat-matrix. -
deviance
The deviance. -
ed
The effective dimension of the model. -
aic
The value of the AIC. -
bic
The value of the BIC. -
Bbases
a list with the B-spline basesBu
andBs
-
-
optimal_logrho
A vector with the optimal values oflog10(rho_u)
andlog10(rho_s)
. -
P_optimal
The optimal penalty matrix P. -
AIC
(ifpar_gridsearch$return_aic == TRUE
) The matrix of AIC values. -
BIC
(ifpar_gridsearch$return_bic == TRUE
) The matrix of BIC values.
Objects of class haz2tsLMM
have a slight different structure. They are
a list with:
-
optimal_model
an object of classLMMsolve
-
AIC_BIC
a list with, among other things, the AIC and BIC values and the ED of the model -
n_events
the number of events -
nu
the number of bins over the u-axis -
ns
the number of bins over the s-axis -
cu
the number of B-splines over the u-axis -
cs
the number of B-splines over the s-axis -
covariates
an indicator for PH model
References
Boer, Martin P. 2023. “Tensor Product P-Splines Using a Sparse Mixed Model Formulation.” Statistical Modelling 23 (5-6): 465–79. https://doi.org/10.1177/1471082X231178591. Carollo, Angela, Paul H. C. Eilers, Hein Putter, and Jutta Gampe. 2023. “Smooth Hazards with Multiple Time Scales.” arXiv Preprint: https://arxiv.org/abs/http://arxiv.org/abs/2305.09342v1
Examples
# Create some fake data - the bare minimum
id <- 1:20
u <- c(5.43, 3.25, 8.15, 5.53, 7.28, 6.61, 5.91, 4.94, 4.25, 3.86, 4.05, 6.86,
4.94, 4.46, 2.14, 7.56, 5.55, 7.60, 6.46, 4.96)
s <- c(0.44, 4.89, 0.92, 1.81, 2.02, 1.55, 3.16, 6.36, 0.66, 2.02, 1.22, 3.96,
7.07, 2.91, 3.38, 2.36, 1.74, 0.06, 5.76, 3.00)
ev <- c(1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1)#'
fakedata <- as.data.frame(cbind(id, u, s, ev))
fakedata2ts <- prepare_data(data = fakedata,
u = "u",
s_out = "s",
ev = "ev",
ds = .5)
# Fit a fake model - not optimal smoothing
fit2ts(fakedata2ts,
optim_method = "grid_search",
lrho = list(seq(1, 1.5, .5), seq(1, 1.5, .5)))
# For more examples please check the vignettes!!! Running more complicated examples
# here would imply longer running times...