#| child: aaa.Rmd
#| include: false

r descr_models("proportional_hazards", "glmnet")

Tuning Parameters

#| label: glmnet-param-info
#| echo: false
defaults <- 
  tibble::tibble(parsnip = c("penalty", "mixture"),
                 default = c("see below", "1.0"))

param <-
proportional_hazards() |> 
  set_engine("glmnet") |> 
  make_parameter_list(defaults)

This model has r nrow(param) tuning parameters:

#| label: glmnet-param-list
#| echo: false
#| results: asis
param$item

The penalty parameter has no default and requires a single numeric value. For more details about this, and the glmnet model in general, see [parsnip::glmnet-details]. As for mixture:

Translation from parsnip to the original package

r uses_extension("proportional_hazards", "glmnet", "censored regression")

#| label: glmnet-creg
library(censored)

proportional_hazards(penalty = double(1), mixture = double(1)) |> 
  set_engine("glmnet") |> 
  translate()

Preprocessing requirements

#| child: template-makes-dummies.Rmd
#| child: template-same-scale.Rmd

By default, [glmnet::glmnet()] uses the argument standardize = TRUE to center and scale the data.

Other details

The model does not fit an intercept.

The model formula (which is required) can include special terms, such as [survival::strata()]. This allows the baseline hazard to differ between groups contained in the function. (To learn more about using special terms in formulas with tidymodels, see [?model_formula][parsnip::model_formula].) The column used inside strata() is treated as qualitative no matter its type. This is different than the syntax offered by the [glmnet::glmnet()] package (i.e., [glmnet::stratifySurv()]) which is not recommended here.

For example, in this model, the numeric column rx is used to estimate two different baseline hazards for each value of the column:

#| include: false
library(survival)
library(censored)
library(dplyr)
library(tidyr)
#| warning: false
library(survival)
library(censored)
library(dplyr)
library(tidyr)

mod <- 
  proportional_hazards(penalty = 0.01) |> 
  set_engine("glmnet", nlambda = 5) |> 
  fit(Surv(futime, fustat) ~ age + ecog.ps + strata(rx), data = ovarian)

pred_data <- data.frame(age = c(50, 50), ecog.ps = c(1, 1), rx = c(1, 2))

# Different survival probabilities for different values of 'rx'
predict(mod, pred_data, type = "survival", time = 500) |> 
  bind_cols(pred_data) |> 
  unnest(.pred)

Note that columns used in the strata() function will also be estimated in the regular portion of the model (i.e., within the linear predictor).

#| child: template-survival-mean.Rmd

Linear predictor values

#| child: template-censored-linear-predictor.Rmd

Case weights

#| child: template-uses-case-weights.Rmd

Saving fitted model objects

#| child: template-butcher.Rmd

References



Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on June 8, 2025, 12:10 p.m.