Skip to contents

This function preprocesses survival data for a Cox transfer analysis. It performs several steps including extracting the response and covariates from a model frame, standardizing the covariates, ensuring the validity of offsets and grouping, and sorting the data by survival time in descending order.

Usage

preprocess(formula, data, group, offset)

Arguments

formula

A formula specifying the survival model (e.g., Surv(time, status) ~ covariates).

data

A data frame containing the variables referenced in the formula.

group

Optional grouping vector.

offset

Optional offset vector.

Value

A list with the following components:

x

A matrix of standardized covariates.

time

A vector of survival times, sorted in descending order.

status

A vector of censoring indicators, corresponding to the sorted survival times.

group

A factor vector representing the group classification for each sample, sorted by time.

offset

A numeric vector representing offsets for each sample, sorted by time.

Details

The function first creates a model frame from the provided formula and data, then extracts the response variable, which should contain the survival time and censoring status. The covariates are extracted using a model matrix and standardized using the scale function. The function also checks the group and offset arguments, assigning default values if they are not provided. Finally, all components (time, status, covariates, group, and offset) are sorted in descending order based on the survival time.