| 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 'mlrMBO'. The accompanying vignette describes the methodology used in 'tramnet' in detail. Transformation models and model-based optimization are described in Hothorn et al. (2019) <doi:10.1111/sjos.12291> and Bischl et al. (2016) <doi:10.48550/arXiv.1703.03373>, respectively. |
| Authors: | Lucas Kook [cre, aut], Balint Tamasi [ctb], Sandra Siegfried [ctb], Samuel Pawel [ctb], Torsten Hothorn [ctb] (ORCID: <https://orcid.org/0000-0001-8301-0471>) |
| Maintainer: | Lucas Kook <[email protected]> |
| License: | GPL-2 |
| Version: | 0.0-992 |
| Built: | 2026-06-09 14:07:14 UTC |
| Source: | https://codeberg.org/LucasKook/tramnet |
"tramnet"
coef method for class "tramnet"
## S3 method for class 'tramnet' coef(object, with_baseline = FALSE, tol = 1e-06, ...)## S3 method for class 'tramnet' coef(object, with_baseline = FALSE, tol = 1e-06, ...)
object |
object of class |
with_baseline |
If |
tol |
tolerance when an estimate should be considered 0
and not returned (default: |
... |
Additional arguments to coef |
Numeric vector containing the model shift parameter estimates
Torsten Hothorn, Lucas Kook
"tramnet_Lm"
coef method for class "tramnet_Lm"
## S3 method for class 'tramnet_Lm' coef(object, with_baseline = FALSE, tol = 1e-06, as.lm = FALSE, ...)## S3 method for class 'tramnet_Lm' coef(object, with_baseline = FALSE, tol = 1e-06, as.lm = FALSE, ...)
object |
object of class |
with_baseline |
If |
tol |
tolerance when an estimate should be considered 0
and not returned (default: |
as.lm |
If TRUE parameters are rescaled to the usual parametrization of lm |
... |
Additional arguments to coef |
Numeric vector containing the linear model shift parameter estimates
Torsten Hothorn, Lucas Kook
data(cars) m0 <- Lm(dist ~ 1, data = cars) x <- as.matrix(cars[, "speed", drop = FALSE]) mt <- tramnet(m0, x = x, alpha = 0, lambda = 0) coef(mt) coef(mt, with_baseline = TRUE) coef(mt, as.lm = TRUE) coef(lm(dist ~ speed, data = cars))data(cars) m0 <- Lm(dist ~ 1, data = cars) x <- as.matrix(cars[, "speed", drop = FALSE]) mt <- tramnet(m0, x = x, alpha = 0, lambda = 0) coef(mt) coef(mt, with_baseline = TRUE) coef(mt, as.lm = TRUE) coef(lm(dist ~ speed, data = cars))
"tramnet" modelsk-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 hyperparameters as an object of
class "cvl_tramnet"
Lucas Kook
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)) }
This function generates an objective function for model-based optimization
based on the cross-validated log-likelihood of a tramnet model with
an elastic net penalty. It is not intended to be called by the user directly,
instead it will be given as an argument to mbo_tramnet.
elnet_obj( object, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds, noisy = FALSE, fold )elnet_obj( object, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds, noisy = FALSE, fold )
object |
object of class |
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: |
fold |
fold for cross validation |
Single objective function for model based optimization.
"tramnet"
estfun method for class "tramnet" which computes
the score contributions w.r.t. each model parameter.
## S3 method for class 'tramnet' estfun( x, parm = coef(x, with_baseline = TRUE, tol = 0), w = NULL, newdata, ... )## S3 method for class 'tramnet' estfun( x, parm = coef(x, with_baseline = TRUE, tol = 0), w = NULL, newdata, ... )
x |
object of class |
parm |
parameters for evaluating the score |
w |
weights |
newdata |
data on which to compute the score contributions |
... |
additional arguments to |
Matrix of score contributions w.r.t. model parameters
evaluated at parm
Lucas Kook
This function generates an objective function for model-based optimization
based on the cross-validated log-likelihood of a tramnet model with
a lasso penalty only. It is not intended to be called by the user directly,
instead it will be given as an argument to mbo_tramnet.
lasso_obj(object, minlambda = 0, maxlambda = 16, folds, noisy = FALSE, fold)lasso_obj(object, minlambda = 0, maxlambda = 16, folds, noisy = FALSE, fold)
object |
object of class |
minlambda |
minimum value for lambda (default: |
maxlambda |
maximum value for lambda (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: |
fold |
fold for cross validation |
Single objective function for model based optimization.
"tramnet"
logLik method for class "tramnet"
## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata, ... )## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata, ... )
object |
object of class |
parm |
parameters to evaluate the log likelihood at |
w |
weights |
newdata |
data to evaluate the log likelihood at |
... |
Additional arguments to logLik |
returns potentially weighted (w) log-likelihood based on
object evaluated at parameters parm and data newdata
Lucas Kook, Torsten Hothorn
Extracts the "optimal" tuning parameters from an object of class
"MBOSingleObjResult" and fits the corresponding tramnet model
mbo_recommended(mbo_obj, m0, x, ...)mbo_recommended(mbo_obj, m0, x, ...)
mbo_obj |
object return by |
m0 |
null model of class |
x |
matrix of covariables |
... |
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 mlrMBO 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_design = 5, n_iter = 5, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds = NULL, learner = "regr.km", pred.type = "se", opt_crit = makeMBOInfillCritEI(), noisy = FALSE, obj_type = c("lasso", "ridge", "elnet"), verbose = TRUE, ... )mbo_tramnet( object, fold = 2, n_design = 5, n_iter = 5, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds = NULL, learner = "regr.km", pred.type = "se", opt_crit = makeMBOInfillCritEI(), noisy = FALSE, obj_type = c("lasso", "ridge", "elnet"), verbose = TRUE, ... )
object |
object of class |
fold |
fold for cross validation |
n_design |
results in |
n_iter |
number of iterations in the model based optimization procedure |
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) |
learner |
type of leaner used for the optimization (default: |
pred.type |
prediction type of the learner (default: |
opt_crit |
optimization criterion, default: expected improvement |
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: |
... |
additional arguments are ignored |
returns an object of class "MBOSingleObjResult" which is
documented in mbo
"prof_*" classesPlot 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 logLik trajectory should be plotted (default: |
... |
additional arguments to |
None
Lucas Kook
library("tramnet") 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) }library("tramnet") 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"
plot method for class "tramnet"
## S3 method for class 'tramnet' plot( x, newdata, 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, 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 |
data used to predict and plot |
type |
type of plot produced |
q |
vector of quantiles |
prob |
vector of probabilities |
K |
number of data points to plot |
col |
see |
lty |
see |
add |
see |
... |
additional options to |
None
Lucas Kook
"tramnet"
predict method for class "tramnet"
## S3 method for class 'tramnet' predict(object, newdata = .get_tramnet_data(object), ...)## S3 method for class 'tramnet' predict(object, newdata = .get_tramnet_data(object), ...)
object |
object of class |
newdata |
data used for prediction |
... |
Additional arguments to |
Vector of predictions based on object evaluated at each row
of newdata
Lucas Kook
"tramnet"
print summary method for class "tramnet"
## S3 method for class 'summary.tramnet' print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'summary.tramnet' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
object of class |
digits |
number of digits to print |
... |
additional arguments |
prints textual summary in the console and returns an invisible copy of the
"tramnet" object
Lucas Kook
"tramnet"
print method for class "tramnet"
## S3 method for class 'tramnet' print(x, ...)## S3 method for class 'tramnet' print(x, ...)
x |
object of class |
... |
additional arguments to |
prints textual summary in the console and returns an invisible copy of the
"tramnet" object
Lucas Kook
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 |
model of class tramnet |
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
Lucas Kook
library("tramnet") 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) }library("tramnet") 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 |
model 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
Lucas Kook
library("tramnet") 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) }library("tramnet") 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) }
"tramnet"
residuals method for class "tramnet"
## S3 method for class 'tramnet' residuals( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata, ... )## S3 method for class 'tramnet' residuals( object, parm = coef(object, tol = 0, with_baseline = TRUE), w = NULL, newdata, ... )
object |
object of class |
parm |
parameters to evaluate score at |
w |
weights |
newdata |
data to evaluate score at |
... |
additional arguments to |
Returns a numeric vector of residuals for each row in newdata
Lucas Kook
This function generates an objective function for model-based optimization
based on the cross-validated log-likelihood of a tramnet model with
a ridge penalty only. It is not intended to be called by the user directly,
instead it will be given as an argument to mbo_tramnet.
ridge_obj(object, minlambda = 0, maxlambda = 16, folds, noisy = FALSE, fold)ridge_obj(object, minlambda = 0, maxlambda = 16, folds, noisy = FALSE, fold)
object |
object of class |
minlambda |
minimum value for lambda (default: |
maxlambda |
maximum value for lambda (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: |
fold |
fold for cross validation |
Single objective function for model based optimization.
"tramnet"
simulate method for class "tramnet"
## S3 method for class 'tramnet' simulate( object, nsim = 1, seed = NULL, newdata = .get_tramnet_data(object), bysim = TRUE, ... )## S3 method for class 'tramnet' simulate( object, nsim = 1, seed = NULL, newdata = .get_tramnet_data(object), bysim = TRUE, ... )
object |
object of class |
nsim |
number of simulation |
seed |
random number generator seed |
newdata |
new data to simulate from |
bysim |
see |
... |
Additional arguments to |
returns a list of data.frames containing parametric bootstrap
samples based on the data supplied in newdata
Lucas Kook
"tramnet"
summary method for class "tramnet"
## S3 method for class 'tramnet' summary(object, ...)## S3 method for class 'tramnet' summary(object, ...)
object |
object of class |
... |
additional arguments |
Returns an object of class "summary.tramnet" containing
information about the model, optimization status, sparsity and
tuning parameters
Lucas Kook
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.
tramnet(model, x, lambda, alpha, constraints = NULL, ...)tramnet(model, x, lambda, alpha, constraints = NULL, ...)
model |
an object of class |
x |
a numeric matrix, where each row corresponds to the same row in the
|
lambda |
a positive penalty parameter for the whole penalty function |
alpha |
a mixing parameter (between zero and one) defining the fraction between absolute and quadratic penalty terms |
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 parameters to |
An object of class "tramnet" with coef, logLik,
summary, simulate, residuals and plot methods
Lucas Kook, Balint Tamasi, Sandra Sigfried
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) }