cox_knockoff_analysis: Complete Cox Knockoff Analysis Workflow

View source: R/main.R

cox_knockoff_analysisR Documentation

Complete Cox Knockoff Analysis Workflow

Description

Performs a complete Multiple knockoff analysis following the four-step workflow: 1. Generate knockoff variables from PLINK data and save to GDS format 2. Fit null Cox model using optimized Cox regression for large-scale analysis 3. Perform SPA testing using original and knockoff variables 4. Apply knockoff filter for variable selection with FDR control

Usage

cox_knockoff_analysis(
  plink_prefix,
  time,
  status,
  covariates = NULL,
  sample_ids = NULL,
  null_model = NULL,
  gds_file = NULL,
  M = 5,
  fdr = 0.05,
  method = "median",
  output_dir = NULL
)

Arguments

plink_prefix

Character string. Path prefix for PLINK files (.bed, .bim, .fam)

time

Numeric vector. Survival times

status

Numeric vector. Censoring indicator (1 = event, 0 = censored)

covariates

Data frame or matrix. Covariate data (optional)

sample_ids

Character vector. Sample IDs to match with genetic data (optional)

null_model

Fitted Cox model object for null hypothesis (optional)

gds_file

Character string. Path to pre-generated GDS file with knockoffs (optional)

M

Integer. Number of knockoff copies to generate (default: 5)

fdr

Numeric. Target false discovery rate (default: 0.05)

method

Character. Method for computing W statistics ("median", "difference", "ratio")

output_dir

Character string. Directory to save intermediate results (default: NULL, uses tempdir())

Value

List containing:

selected_vars

Indices of selected variables

W_stats

W statistics for all variables

threshold

Knockoff threshold used

gds_file

Path to GDS file used

null_model

Fitted null Cox model

test_results

SPA test results

List containing:

  • W_stats - Vector of W statistics for each variant

  • selected_vars - Indices of selected variants

  • knockoffs - Generated knockoff matrix (if gds_file not provided)

  • summary - Summary statistics of the analysis

Examples


# Simple workflow example
# Load example data
extdata_path <- system.file('extdata', package = 'CoxMK')
plink_prefix <- file.path(extdata_path, 'sample')
pheno_data <- read.table(file.path(extdata_path, 'tte_phenotype.txt'), 
                        header = TRUE, stringsAsFactors = FALSE)
covar_data <- read.table(file.path(extdata_path, 'covariates.txt'), 
                        header = TRUE, stringsAsFactors = FALSE)
covar_data <- covar_data[, c("age", "sex", "bmi", "smoking")]

# Run complete analysis
result <- cox_knockoff_analysis(
  plink_prefix = plink_prefix,
  time = pheno_data$time,
  status = pheno_data$status,
  covariates = covar_data,
  M = 3,
  fdr = 0.1
)

# View results
print(result$selected_vars)
print(result$summary)


CoxMK documentation built on Sept. 9, 2025, 5:24 p.m.