tramnet: Regularised Transformation Models

View source: R/tramnet.R

tramnetR Documentation

Regularised Transformation Models

Description

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.

Usage

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,
  ...
)

Arguments

model

an object of class "tram" as returned by any of the modelling functions from package tram (default method) or a formula describing the model (formula method)

...

additional parameters to psolve (default method) or to tram (formula method), e.g., distribution, transformation, order or log_first

x

a numeric matrix, where each row corresponds to the same row in the data argument used to fit model

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 NAs

Details

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.

Value

An object of class "tramnet" with coef, logLik, summary, simulate, residuals, predict, model.matrix and plot methods

Author(s)

Lucas Kook, Balint Tamasi, Sandra Sigfried

Examples


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)
}


tramnet documentation built on Oct. 16, 2026, 5:07 p.m.