Title: | Penalized Transformation Models |
---|---|
Description: | Partially penalized versions of specific transformation models implemented in package 'mlt'. Available models include a fully parametric version of the Cox model, other parametric survival models (Weibull, etc.), models for binary and ordered categorical variables, normal and transformed-normal (Box-Cox type) linear models, and continuous outcome logistic regression. Hyperparameter tuning is facilitated through model-based optimization functionalities from package 'mlr3MBO'. The methodology is described in Kook et al. (2021) <doi:10.32614/RJ-2021-054>. Transformation models and model-based optimization are described in Hothorn et al. (2019) <doi:10.1111/sjos.12291> and Bischl et al. (2016) <arxiv:1703.03373>, respectively. |
Authors: | Lucas Kook [cre, aut] , Balint Tamasi [ctb], Sandra Siegfried [ctb], Samuel Pawel [ctb], Torsten Hothorn [ctb] |
Maintainer: | Lucas Kook <[email protected]> |
License: | GPL-2 |
Version: | 0.1-0 |
Built: | 2024-11-19 19:21:31 UTC |
Source: | https://github.com/r-forge/ctm |
k-fold cross validation for "tramnet"
objects over a grid of
the tuning parameters based on out-of-sample log-likelihood.
cvl_tramnet( object, fold = 2, lambda = 0, alpha = 0, folds = NULL, fit_opt = FALSE )
cvl_tramnet( object, fold = 2, lambda = 0, alpha = 0, folds = NULL, fit_opt = FALSE )
object |
Object of class |
fold |
Number of folds for cross validation. |
lambda |
Values for lambda to iterate over. |
alpha |
Values for alpha to iterate over. |
folds |
Manually specify folds for comparison with other methods. |
fit_opt |
If |
Returns out-of-sample logLik and coefficient estimates for
corresponding folds and values of the hyper-parameters as an object of
class "cvl_tramnet"
set.seed(241068) if (require("survival") & require("TH.data")) { data("GBSG2", package = "TH.data") X <- 1 * matrix(GBSG2$horTh == "yes", ncol = 1) colnames(X) <- "horThyes" GBSG2$surv <- with(GBSG2, Surv(time, cens)) m <- Coxph(surv ~ 1, data = GBSG2, log_first = TRUE) mt <- tramnet(model = m, x = X, lambda = 0, alpha = 0) mc <- Coxph(surv ~ horTh, data = GBSG2) cvl_tramnet(mt, fold = 2, lambda = c(0, 1), alpha = c(0, 1)) }
set.seed(241068) if (require("survival") & require("TH.data")) { data("GBSG2", package = "TH.data") X <- 1 * matrix(GBSG2$horTh == "yes", ncol = 1) colnames(X) <- "horThyes" GBSG2$surv <- with(GBSG2, Surv(time, cens)) m <- Coxph(surv ~ 1, data = GBSG2, log_first = TRUE) mt <- tramnet(model = m, x = X, lambda = 0, alpha = 0) mc <- Coxph(surv ~ horTh, data = GBSG2) cvl_tramnet(mt, fold = 2, lambda = c(0, 1), alpha = c(0, 1)) }
Regularized transformation model classes
LmNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) BoxCoxNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) ColrNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) SurvregNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) CoxphNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) LehmannNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) PolrNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... )
LmNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) BoxCoxNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) ColrNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) SurvregNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) CoxphNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) LehmannNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... ) PolrNET( formula, data, lambda = 0, alpha = 1, tram_args = NULL, constraints = NULL, ... )
formula |
Formula specifying the regression. See |
data |
Object of class |
lambda |
A positive penalty parameter for the whole penalty function. |
alpha |
A mixing parameter (between zero and one) defining the fraction
between lasso and ridge penalties, where |
tram_args |
Additional arguments (besides |
constraints |
An optional list containing a matrix of linear inequality contraints on the regression coefficients and a vector specifying the rhs of the inequality. |
... |
Additional arguments passed to |
Object of class "tramnet"
.
"tramnet"
S3 methods for class "tramnet"
## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata = NULL, add_penalty = FALSE, ... ) ## S3 method for class 'tramnet' coef(object, with_baseline = FALSE, tol = 1e-06, ...) ## S3 method for class 'tramnet_Lm' coef(object, with_baseline = FALSE, tol = 1e-06, as.lm = FALSE, ...) ## S3 method for class 'tramnet' predict(object, newdata = NULL, ...) ## S3 method for class 'tramnet' simulate(object, nsim = 1, seed = NULL, newdata = NULL, bysim = TRUE, ...) ## S3 method for class 'tramnet' estfun( x, parm = coef(x, with_baseline = TRUE, tol = 0), w = NULL, newdata = NULL, ... ) ## S3 method for class 'tramnet' residuals( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata = NULL, ... ) ## S3 method for class 'tramnet' print(x, ...) ## S3 method for class 'tramnet' summary(object, ...) ## S3 method for class 'summary.tramnet' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata = NULL, add_penalty = FALSE, ... ) ## S3 method for class 'tramnet' coef(object, with_baseline = FALSE, tol = 1e-06, ...) ## S3 method for class 'tramnet_Lm' coef(object, with_baseline = FALSE, tol = 1e-06, as.lm = FALSE, ...) ## S3 method for class 'tramnet' predict(object, newdata = NULL, ...) ## S3 method for class 'tramnet' simulate(object, nsim = 1, seed = NULL, newdata = NULL, bysim = TRUE, ...) ## S3 method for class 'tramnet' estfun( x, parm = coef(x, with_baseline = TRUE, tol = 0), w = NULL, newdata = NULL, ... ) ## S3 method for class 'tramnet' residuals( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata = NULL, ... ) ## S3 method for class 'tramnet' print(x, ...) ## S3 method for class 'tramnet' summary(object, ...) ## S3 method for class 'summary.tramnet' print(x, digits = max(3L, getOption("digits") - 3L), ...)
object |
Object of class |
parm |
Parameters to evaluate the log likelihood at. |
w |
Optional vector of sample weights. |
newdata |
Data to evaluate the log likelihood at. |
add_penalty |
Whethr or not to return the penalized log-likelihood
(default |
... |
Ignored. |
with_baseline |
If |
tol |
Tolerance when an estimate should be considered 0 and not
returned (default |
as.lm |
See |
nsim |
Number of simulations, see |
seed |
Random seed, see |
bysim |
Return by simulation, see |
x |
Object of class |
digits |
Number of digits to print. |
Returns (potentially weighted w
) log-likelihood based on
object
evaluated at parameters parm
and data newdata
Numeric vector containing the model shift parameter estimates
Numeric vector containing the linear model shift parameter estimates
Vector of predictions based on object
evaluated at each row
of newdata
Returns a list
of data.frames
containing parametric
bootstrap samples of the response based on the data supplied in
newdata
Matrix of score contributions w.r.t. model parameters evaluated at
parm
Returns a numeric vector of residuals for each row in newdata
Object of class "summary.tramnet"
.
Object of class "summary.tramnet"
.
Invisible x
.
Extracts the "optimal" tuning parameters from the output of
mbo_tramnet
and fits the corresponding tramnet
model.
mbo_recommended(mbo_obj, m0, x, ...)
mbo_recommended(mbo_obj, m0, x, ...)
mbo_obj |
Object returned by |
m0 |
Null model of class |
x |
Design matrix, see |
... |
Additional arguments to |
Object of class "tramnet"
.
Uses model based optimization to find the optimal tuning
parameter(s) in a regularized transformation model based on
cross-validated log-likelihoods. Here the 'tramnet'
package makes
use of the 'mlr3mbo'
interface for Bayesian Optimization in
machine learning problems to maximize the cv-logLik as a black-box
function of the tuning parameters alpha and lambda.
mbo_tramnet( object, fold = 2, n_iter = 5, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds = NULL, noisy = FALSE, obj_type = c("lasso", "ridge", "elnet"), verbose = TRUE, ... )
mbo_tramnet( object, fold = 2, n_iter = 5, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds = NULL, noisy = FALSE, obj_type = c("lasso", "ridge", "elnet"), verbose = TRUE, ... )
object |
Object of class |
fold |
Number of cross validation folds. |
n_iter |
Maximum number of iterations in model-based optimization routine. |
minlambda |
Minimum value for lambda (default |
maxlambda |
Maximum value for lambda (default |
minalpha |
Minimum value for alpha (default |
maxalpha |
Maximum value for alpha (default |
folds |
Self specified folds for cross validation (mainly for reproducibility and comparability purposes). |
noisy |
indicates whether folds for k-fold cross-validation should
be random for each iteration, leading to a noisy objective function
(default |
obj_type |
Objective type, one of |
verbose |
Toggle for a verbose output (default |
... |
Currently ignored. |
See Optimizer
's optimize
function which
returns a data.table::data.table
.
Plot regularization paths and optionally log-likelihood
trajectories of objects of class "prof_alpha"
and
"prof_lambda"
. Coefficient names are automatically added to the
plot.
plot_path(object, plot_logLik = FALSE, ...)
plot_path(object, plot_logLik = FALSE, ...)
object |
Object of class |
plot_logLik |
Whether |
... |
Additional arguments to |
None.
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit1 <- tramnet(y, x, lambda = 0, alpha = 1) pfl <- prof_lambda(fit1) plot_path(pfl) fit2 <- tramnet(y, x, lambda = 1, alpha = 1) pfa <- prof_alpha(fit2) plot_path(pfa) }
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit1 <- tramnet(y, x, lambda = 0, alpha = 1) pfl <- prof_lambda(fit1) plot_path(pfl) fit2 <- tramnet(y, x, lambda = 1, alpha = 1) pfa <- prof_alpha(fit2) plot_path(pfa) }
"tramnet"
objectsPlot "tramnet"
objects
## S3 method for class 'tramnet' plot( x, newdata = NULL, type = c("distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "quantile", "trafo"), q = NULL, prob = 1:(K - 1)/K, K = 50, col = rgb(0.1, 0.1, 0.1, 0.1), lty = 1, add = FALSE, ... )
## S3 method for class 'tramnet' plot( x, newdata = NULL, type = c("distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "quantile", "trafo"), q = NULL, prob = 1:(K - 1)/K, K = 50, col = rgb(0.1, 0.1, 0.1, 0.1), lty = 1, add = FALSE, ... )
x |
Object of class |
newdata |
See |
type |
See |
q |
See |
prob |
See |
K |
See |
col |
See |
lty |
See |
add |
See |
... |
Additional arguments passed to |
Computes the regularization path of all coefficients for a single tuning, alpha, parameter over a sequence of values.
prof_alpha(model, min_alpha = 0, max_alpha = 1, nprof = 5, as.lm = FALSE)
prof_alpha(model, min_alpha = 0, max_alpha = 1, nprof = 5, as.lm = FALSE)
model |
Object of class |
min_alpha |
Minimal value of alpha (default |
max_alpha |
Maximal value of alpha (default |
nprof |
Number of profiling steps (default |
as.lm |
Return scaled coefficients for class |
Object of class "prof_alpha"
which contains the regularization
path of all coefficients and the log-likelihood over the mixing parameter
alpha
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit <- tramnet(y, x, lambda = 1, alpha = 1) pfa <- prof_alpha(fit) plot_path(pfa) }
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit <- tramnet(y, x, lambda = 1, alpha = 1) pfa <- prof_alpha(fit) plot_path(pfa) }
Computes the regularization path of all coefficients for a single tuning parameter, lambda, over a sequence of values.
prof_lambda(model, min_lambda = 0, max_lambda = 15, nprof = 5, as.lm = FALSE)
prof_lambda(model, min_lambda = 0, max_lambda = 15, nprof = 5, as.lm = FALSE)
model |
Object of class |
min_lambda |
Minimal value of lambda (default |
max_lambda |
Maximal value of lambda (default |
nprof |
Number of profiling steps (default |
as.lm |
Return scaled coefficients for class |
Object of class "prof_lambda"
which contains the
regularization path of all coefficients and the log-likelihood over the
penalty parameter lambda
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit <- tramnet(y, x, lambda = 0, alpha = 1) pfl <- prof_lambda(fit) plot_path(pfl) }
if (require("survival") & require("penalized")) { data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit <- tramnet(y, x, lambda = 0, alpha = 1) pfl <- prof_lambda(fit) plot_path(pfl) }
Regularized transformation models
tramnet(model, ...) ## S3 method for class 'formula' tramnet( model, data, lambda, alpha, tram_fun, tram_args = NULL, constraints = NULL, groups = NULL, ... ) ## S3 method for class 'tram' tramnet(model, x, lambda, alpha, constraints = NULL, groups = NULL, ...)
tramnet(model, ...) ## S3 method for class 'formula' tramnet( model, data, lambda, alpha, tram_fun, tram_args = NULL, constraints = NULL, groups = NULL, ... ) ## S3 method for class 'tram' tramnet(model, x, lambda, alpha, constraints = NULL, groups = NULL, ...)
model |
Either a |
... |
Additional arguments passed to |
data |
Object of class |
lambda |
A positive penalty parameter for the whole penalty function. |
alpha |
A mixing parameter (between zero and one) defining the fraction
between lasso and ridge penalties, where |
tram_fun |
Character referring to an implementation in package
|
tram_args |
Additional arguments (besides |
constraints |
An optional list containing a matrix of linear inequality contraints on the regression coefficients and a vector specifying the rhs of the inequality. |
groups |
For group lasso penalties, groups can be supplied as a vector
of consecutive integers of the same length as columns in |
x |
A numeric matrix, where each row corresponds to the same row in the
|
Partially penalized and constrained transformation models,
including Cox models and continuous outcome logistic regression.
The methodology is described in the tramnet
vignette
accompanying this package.
An object of class "tramnet"
with coef
, logLik
,
summary
, simulate
, residuals
and plot
methods
Lucas Kook and Torsten Hothorn, The R Journal (2021) 13:1, pages 581-594. doi:10.32614/RJ-2021-054
if (require("penalized") & require("survival")) { ## --- Comparison with penalized data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) fit <- penalized(response = resp, penalized = x, lambda1 = 1, lambda2 = 0, standardize = FALSE, data = nki70) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit2 <- tramnet(y, x, lambda = 1, alpha = 1) ## L1 only coef(fit) coef(fit2) }
if (require("penalized") & require("survival")) { ## --- Comparison with penalized data("nki70", package = "penalized") nki70$resp <- with(nki70, Surv(time, event)) x <- scale(model.matrix( ~ 0 + DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70)) fit <- penalized(response = resp, penalized = x, lambda1 = 1, lambda2 = 0, standardize = FALSE, data = nki70) y <- Coxph(resp ~ 1, data = nki70, order = 10, log_first = TRUE) fit2 <- tramnet(y, x, lambda = 1, alpha = 1) ## L1 only coef(fit) coef(fit2) }