无论是生存结局影响因素研究,还是近些年非常火爆的临床预测模型(基于生存数据建立的临床预测模型通常称为预后模型),单因素COX回归常用来进行危险因素的筛选,如果指标不多,10个以内,工作量还可以接受。如果指标(变量)达到10个,甚至是几十个,这个工作量就会有些太大了。
掌握一个批量完成单因素COX回归的方法显然是很有必要的。
1、安装ezcox包并调用
#install.packages("ezcox")library(ezcox)library(survival) #为了使用自带数据集
2、查看所用数据集
lungstr(lung)?lung

lung {survival} R DocumentationNCCTG Lung Cancer DataDescriptionSurvival in patients with advanced lung cancer from the North Central Cancer Treatment Group. Performance scores rate how well the patient can perform usual daily activities.inst: Institution codetime: Survival time in daysstatus: censoring status 1=censored, 2=deadage: Age in yearssex: Male=1 Female=2ph.ecog: ECOG performance score as rated by the physician. 0=asymptomatic, 1= symptomatic but completely ambulatory, 2= in bed <50% of the day, 3= in bed > 50% of the day but not bedbound, 4 = bedboundph.karno: Karnofsky performance score (bad=0-good=100) rated by physicianpat.karno: Karnofsky performance score as rated by patientmeal.cal: Calories consumed at mealswt.loss: Weight loss in last six months
3、分类变量因子化
lung$sex <- factor(lung$sex)lung$ph.ecog <- factor(lung$ph.ecog)str(lung)

4、批量完成单因素Cox回归分析
results <- ezcox(lung, time = "time",status = "status",covariates = c("age", "sex", "ph.ecog","ph.karno","pat.karno","meal.cal","wt.loss"))
5、查看单因素COX回归分析结果,并导出为CSV文件
5.1直接查看
results

5.2表格查看
knitr::kable(results)

5.3把结果直接输出为CSV格式,可以直接用EXCEL打开。
write.csv(results,"results.csv")
