Stata極簡生存分析

1. 導入數據

webuse drugtr,clear
*webuse -- Use dataset from Stata website
stset,clear
*上一行命令導入進來的數據是「生存時間數據」,會比最原始的數據多四列,這一行命令的目的是重置爲原始數據,之因此這樣作,是爲了顯示數據處理的所有過程
codebook drug
codebook studytime
codebook died
codebook age
*codebook -- Describe data contents

2. 將原始數據轉換爲生存數據

stset studytime,failure(died==1)
*指定生存時間爲studytime列,終止(failure)事件爲died列,其中值爲1表示終止
stsum
stdescribe
sts list
*以上幾個爲描述命令

3. KM生存曲線

sts graph,by(drug)
*畫KM生存曲線
sts graph if age < 50,by(drug)
sts graph,by(drug) risktable
*生存曲線下方加表格

4. log-rank檢驗

sts test drug
*檢驗兩組差別是否顯著,默認爲log-rank檢驗

5. Cox比例風險模型

stcox drug
stcox drug age
*cox比例風險模型,能夠解讀爲控制另外一個(些)變量,當前變量對發生終點事件風險的影響

6. PH假定的檢驗

estat phtest
*Tests of proportional-hazards assumption,零假設爲歸入Cox迴歸模型的變量知足PH假定

stphplot, by(drug)adjust(age)
*by(drug)adjust(age)表示控制age變量看drug對發生終點事件的影響
*從圖形看PH假定,若兩條線近似平行,能夠認爲是成立的

相關文章
相關標籤/搜索