R/permutating_survival.R
permutating_survival.RdThis function fits a per-feature survival model to the original data matrix using permuted sample metadata, generating a null distribution of test statistics for downstream FDR and p-value estimation.
permutating_survival(x, meta.info, formula.str, competing_risks)A data matrix where rows represent features (e.g., proteins, metabolites) and columns represent samples.
A data frame of permuted sample metadata, where each row
corresponds to a sample. Must include time, event, and any
additional covariates used in formula.str.
A string specifying the formula to be used in model
fitting. Must include a Surv(time, event) term. The per-feature
coefficient term (y) is prepended automatically.
Logical. If FALSE (default), a Cox
proportional hazards model is fitted per feature using coxph.
If TRUE, a competing risks model is fitted per
feature using crr from the cmprsk package.
A list containing the following elements:
A numeric vector of absolute Cox coefficients (\(|\beta|\)) for each feature.
A numeric vector of standard errors of the coefficients for each feature.
For each feature (row), the function appends the feature expression values
as y to the permuted metadata and fits either a Cox proportional
hazards model (competing_risks = FALSE) or a
subdistribution hazard model (competing_risks = TRUE). Because
the metadata is permuted, the resulting statistics form the null distribution
used to compute empirical p-values and FDR.
Unlike bootstrap_survival, this function operates directly on the
full data matrix without group splitting or resampling.