基础知识
1.定义:随时间变化的协变量是指在观测过程中数值可能会发生变化的协变量。
2.数据结构:在处理随时间变化的协变量时,PROC PHREG 有两种截然不同的方法来设置数据和指定模型。
第一种,programming statement,每个个体只有一条记录,而时间相关协变量的信息包含在该记录的多个变量中。
第二种,counting process,每个个体可能有多个记录,每条记录对应一个时间间隔。在此期间,所有协变量保持不变。一旦构建了这种特殊的数据集,时间相关协变量的处理方法与时间不变协变量的处理方法相同。然而,在此之前需要产生变量来明确应变量。
案例数据
1.数据来源:Stanford Heart Transplant Data
a time-invariant covariate TRANS that was equal to 1 if the patient ever had a transplant and 0 otherwise.
- a time-dependent covariate PLANT equal to 1 if the patient has already had a transplant at day t; otherwise, PLANT is equal to 0.
- SURG =1 if the patient had previous heart surgery; otherwise, SURG=0.
 4.AGEACCPT is the patient’s age in years at the time of acceptance, and WAIT is the time in days from acceptance until transplant surgery。
程序实现
第一种方法:
PROC PHREG DATA=stan;
 MODEL surv1*dead(0)=plant surg ageaccpt / TIES=EFRON;
 IF wait>=surv1 OR wait=. THEN plant=0; ELSE plant=1;
RUN;
note:
EFRON method is a better default than the usual BRESLOW method
plant=1 代表在t时刻已经移植了,0代表没有移植。IF语句必须在plant之后
第二种方法:
/*整理数据结构*/
DATA stanlong;
SET stan;
plant=0;
start=0;
IF trans=0 THEN DO;
 dead2=dead;
 stop=surv1;
 IF stop=0 THEN stop=.1;
 OUTPUT; 
END;
ELSE DO;
 stop=wait;
 IF stop=0 THEN stop=.1;
 dead2=0;
 OUTPUT;
 plant=1;
 start=wait;
 IF stop=.1 THEN start=.1;
 stop=surv1;
 dead2=dead;
 OUTPUT;
END;
RUN;
/*cox模型分析*/
PROC PHREG DATA=stanlong;
 MODEL (start,stop)*dead2(0)=plant surg ageaccpt /TIES=EFRON; 
RUN;
结果

image.png
参考文献:survival analysis using SAS