CoxTermsearch: This function implments Stepwise model selection by terms of...

View source: R/CoxTermsearch.R

CoxTermsearchR Documentation

This function implments Stepwise model selection by terms of natural cubic splines in Cox regression for latency analysis This is GreadSearching by knots

Description

This function implments Stepwise model selection by terms of natural cubic splines in Cox regression for latency analysis This is GreadSearching by knots

Usage

CoxTermsearch(
  data,
  time_start,
  time_end,
  status,
  exposure,
  knots,
  latency,
  adjusted_variable = NULL,
  adjusted_model = NULL,
  criteria = "AIC"
)

Arguments

data

A data frame containing the data

time_start

start time

time_end

end time

status

survival status. 1 for death and 0 for censored

exposure

Name of the time-varying exposure variable. From the most recent to the furthest in time.

knots

A vector of prespecified knots

latency

prespecified latency

adjusted_variable

A vector of adjusted variables

adjusted_model

A vector of adjusted models

criteria

A string to specify the criteria for model selection. It can be either "AIC" or "BIC". The default is "AIC"

Value

A list. The first element is the best knots with the lowest AIC. The second element is a Cox model

Examples

time_start <- "age_start"
time_end <- "age_end"
status <- "failure"
exposure <- paste0("lag", 0:15)
knots <- seq(0, 15, by = 3)
latency <- 16
adjusted_variable <- "L"
adjusted_model <- "L"
fit <- CoxTermsearch(sim_data, time_start, time_end, status, exposure, knots = knots, latency)
#In this example, we will generate a random covariate L and adjust for it in our model
sim_data$L <- rbinom(nrow(sim_data), 1, 0.5)
adjusted_variable <- "L"
adjusted_model <- "L+I(L^2)"
fit <- CoxTermsearch(sim_data, time_start, time_end, status, exposure, knots = knots, latency,
adjusted_variable = adjusted_variable, adjusted_model = adjusted_model)
#L is selected into the final model but L^2 was not

LatencyA documentation built on Oct. 21, 2026, 5:14 p.m.