| 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.), normal and transformed-normal (Box-Cox type) linear models, and continuous outcome logistic regression. Models can be specified via a formula interface. Hyperparameter tuning is facilitated through model-based optimization functionalities from package 'mlr3mbo'. 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. (2017) <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.1-0 |
| Built: | 2026-10-17 10:27:06 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, scaled = FALSE, ...)## S3 method for class 'tramnet' coef(object, with_baseline = FALSE, tol = 1e-06, scaled = FALSE, ...)
object |
object of class |
with_baseline |
If |
tol |
tolerance when an estimate should be considered 0
and not returned (default: |
scaled |
only for models fitted via the formula interface: If
|
... |
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, scaled = FALSE, ... )## S3 method for class 'tramnet_Lm' coef( object, with_baseline = FALSE, tol = 1e-06, as.lm = FALSE, scaled = 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 |
scaled |
only for models fitted via the formula interface: If
|
... |
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))
Penalized versions of the transformation models implemented in package
tram, specified via a formula. These are convenience wrappers around
tramnet, analogous to the corresponding functions
Coxph, Colr,
Lm, BoxCox,
Lehmann and Survreg.
Coxphnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Colrnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Lmnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) BoxCoxnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Lehmannnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Survregnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... )Coxphnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Colrnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Lmnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) BoxCoxnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Lehmannnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... ) Survregnet( formula, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... )
formula |
an object of class |
data |
an optional data frame containing the variables in the model |
subset |
an optional vector specifying a subset of observations to be used in the fitting process |
weights |
an optional vector of case weights to be used in the fitting process |
offset |
an optional vector of offsets |
na.action |
a function which indicates what should happen when the
data contain |
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 (on the original scale of the covariates) and a vector specifying the rhs of the inequality |
... |
additional arguments to the corresponding function in package
tram, e.g., |
The left-hand side of formula (including strata, as in
y | s ~ x) defines the unpenalized baseline transformation, all
terms on the right-hand side are penalized. The design matrix is obtained
via model.matrix without intercept and its columns are scaled
to unit variance. The scaling of the training data is stored and re-used
whenever newdata is supplied to one of the methods, or in
cvl_tramnet. Coefficients are reported on the original scale
of the covariates, see coef.tramnet.
Not all combinations of error distribution and censoring type lead to
objective functions that can be solved by CVXR; see the table in
the tramnet vignette.
An object of class "tramnet", see tramnet
Lucas Kook
if (require("survival") & require("TH.data")) { data("GBSG2", package = "TH.data") GBSG2$surv <- with(GBSG2, Surv(time, cens)) fit <- Coxphnet(surv ~ horTh + age + tsize + pnodes, data = GBSG2, lambda = 5, alpha = 1, log_first = TRUE) coef(fit) coef(fit, scaled = TRUE) predict(fit, newdata = GBSG2[1:5, ], type = "survivor", q = 1000) } data("cars") fit <- Lmnet(dist ~ speed, data = cars, lambda = 1, alpha = 0) coef(fit, as.lm = TRUE)if (require("survival") & require("TH.data")) { data("GBSG2", package = "TH.data") GBSG2$surv <- with(GBSG2, Surv(time, cens)) fit <- Coxphnet(surv ~ horTh + age + tsize + pnodes, data = GBSG2, lambda = 5, alpha = 1, log_first = TRUE) coef(fit) coef(fit, scaled = TRUE) predict(fit, newdata = GBSG2[1:5, ], type = "survivor", q = 1000) } data("cars") fit <- Lmnet(dist ~ speed, data = cars, lambda = 1, alpha = 0) coef(fit, as.lm = TRUE)
"tramnet" modelsk-fold cross validation for "tramnet" objects over a grid of
the tuning parameters based on out-of-sample log-likelihood.
For models fitted via the formula interface, the covariates are
scaled within each training fold and the test fold is scaled
accordingly.
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)) ## formula interface mf <- Coxphnet(surv ~ horTh + age, data = GBSG2, lambda = 0, alpha = 0, log_first = TRUE) cvl_tramnet(mf, 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)) ## formula interface mf <- Coxphnet(surv ~ horTh + age, data = GBSG2, lambda = 0, alpha = 0, log_first = TRUE) cvl_tramnet(mf, 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 of class
ObjectiveRFun.
"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, scaled = TRUE), w = NULL, newdata, ... )## S3 method for class 'tramnet' estfun( x, parm = coef(x, with_baseline = TRUE, tol = 0, scaled = TRUE), 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 of class
ObjectiveRFun.
"tramnet"
logLik method for class "tramnet"
## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE, scaled = TRUE), w = NULL, newdata, ... )## S3 method for class 'tramnet' logLik( object, parm = coef(object, tol = 0, with_baseline = TRUE, scaled = TRUE), w = NULL, newdata, ... )
object |
object of class |
parm |
parameters to evaluate the log likelihood at (for models fitted via the formula interface, shift parameters refer to the scaled covariates) |
w |
weights, defaults to the weights used for fitting |
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.
If newdata is missing, the penalized log-likelihood of the training
data is returned, otherwise the (unpenalized) out-of-sample
log-likelihood
Lucas Kook, Torsten Hothorn
Extracts the "optimal" tuning parameters from an object returned by
mbo_tramnet 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 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_design = 5, n_iter = 5, minlambda = 0, maxlambda = 16, minalpha = 0, maxalpha = 1, folds = NULL, learner = "regr.km", pred.type = "se", opt_crit = "ei", 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 = "ei", noisy = FALSE, obj_type = c("lasso", "ridge", "elnet"), verbose = TRUE, ... )
object |
object of class |
fold |
fold for cross validation |
n_design |
number of rows of the initial design matrix based on a random latin hypercube design |
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 learner used as surrogate model in the optimization,
either the key of a regression learner in
|
pred.type |
prediction type of the learner (default: |
opt_crit |
optimization criterion, either the key of an acquisition
function in |
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 a list containing the recommended tuning parameters
(x), the corresponding objective value (y), i.e., minus
two times the cross-validated log-likelihood, the type of objective
(obj_type) and the optimization instance (instance) of
class OptimInstanceBatchSingleCrit, which contains
the full archive of evaluated tuning parameters
Lucas Kook
if (require("survival") & require("TH.data") & require("DiceKriging")) { set.seed(241068) data("GBSG2", package = "TH.data") GBSG2$surv <- with(GBSG2, Surv(time, cens)) mt <- Coxphnet(surv ~ horTh + age + tsize + pnodes, data = GBSG2, lambda = 0, alpha = 0, log_first = TRUE) tmbo <- mbo_tramnet(mt, obj_type = "lasso", fold = 2, n_iter = 3, verbose = FALSE) tmbo$x coef(mbo_recommended(tmbo, mt)) }if (require("survival") & require("TH.data") & require("DiceKriging")) { set.seed(241068) data("GBSG2", package = "TH.data") GBSG2$surv <- with(GBSG2, Surv(time, cens)) mt <- Coxphnet(surv ~ horTh + age + tsize + pnodes, data = GBSG2, lambda = 0, alpha = 0, log_first = TRUE) tmbo <- mbo_tramnet(mt, obj_type = "lasso", fold = 2, n_iter = 3, verbose = FALSE) tmbo$x coef(mbo_recommended(tmbo, mt)) }
"tramnet"
model.matrix method for class "tramnet", returning the (scaled)
design matrix of the penalized covariates
## S3 method for class 'tramnet' model.matrix(object, newdata, ...)## S3 method for class 'tramnet' model.matrix(object, newdata, ...)
object |
object of class |
newdata |
optional data frame. For models fitted via the formula
interface, the design matrix is computed from |
... |
additional arguments are ignored |
Numeric matrix of covariates as used for fitting object
(default) or computed from newdata
Lucas Kook
"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, ...)## S3 method for class 'tramnet' predict(object, newdata, ...)
object |
object of class |
newdata |
data used for prediction, defaults to the data used for
fitting |
... |
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, scaled = TRUE), w = NULL, newdata, ... )## S3 method for class 'tramnet' residuals( object, parm = coef(object, tol = 0, with_baseline = TRUE, scaled = 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 of class
ObjectiveRFun.
"tramnet"
simulate method for class "tramnet"
## S3 method for class 'tramnet' simulate(object, nsim = 1, seed = NULL, newdata, bysim = TRUE, ...)## S3 method for class 'tramnet' simulate(object, nsim = 1, seed = NULL, newdata, bysim = TRUE, ...)
object |
object of class |
nsim |
number of simulation |
seed |
random number generator seed |
newdata |
new data to simulate from, defaults to the data used for
fitting |
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, ...) ## Default S3 method: tramnet(model, x, lambda, alpha, constraints = NULL, ...) ## S3 method for class 'formula' tramnet( model, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... )tramnet(model, ...) ## Default S3 method: tramnet(model, x, lambda, alpha, constraints = NULL, ...) ## S3 method for class 'formula' tramnet( model, data, subset, weights, offset, na.action = na.omit, lambda, alpha, constraints = NULL, ... )
model |
an object of class |
... |
additional parameters to |
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. In the formula method, the constraints refer to the coefficients on the original scale of the covariates |
data |
an optional data frame containing the variables in the model |
subset |
an optional vector specifying a subset of observations to be used in the fitting process |
weights |
an optional vector of case weights to be used in the fitting process |
offset |
an optional vector of offsets |
na.action |
a function which indicates what should happen when the
data contain |
The default method takes an unpenalized baseline model of class
"tram", for instance Coxph(y ~ 1, data = d), and a matrix of
covariates x, which should be scaled by the user. The formula method
fits the baseline model and sets up the design matrix in one go. It is the
penalized analogue of tram: the model is
fixed through the arguments distribution and transformation
(and others) passed via ... to tram. Convenience
wrappers such as Coxphnet exist for the most common models.
In the formula method, the left-hand side of model (including
strata, as in y | s ~ x) defines the baseline transformation, all
terms on the right-hand side are penalized. The design matrix is obtained
via model.matrix without intercept and its columns are
scaled to unit variance. They are not centered, since the baseline
transformation absorbs any shift in location. The scaling of the training
data is stored and re-used whenever newdata is supplied, e.g., in
predict, logLik or cvl_tramnet. Coefficients are
reported on the original scale of the covariates, see
coef.tramnet.
An object of class "tramnet" with coef, logLik,
summary, simulate, residuals, predict,
model.matrix 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) ## --- Formula interface, scaling is done internally fit3 <- tramnet(resp ~ DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70, lambda = 1, alpha = 1, distribution = "MinExtrVal", transformation = "smooth", negative = FALSE, order = 10, log_first = TRUE) coef(fit3) coef(fit3, scaled = TRUE) }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) ## --- Formula interface, scaling is done internally fit3 <- tramnet(resp ~ DIAPH3 + NUSAP1 + TSPYL5 + C20orf46, data = nki70, lambda = 1, alpha = 1, distribution = "MinExtrVal", transformation = "smooth", negative = FALSE, order = 10, log_first = TRUE) coef(fit3) coef(fit3, scaled = TRUE) }