Cox 比例風險模型
現在你要在網路商店的資料上估計 Cox 比例風險模型。儲存在 dataNextOrder 的資料現在多了 4 個變數:第一筆訂單的 shoppingCartValue(金額,美元)、顧客是否使用 voucher、該訂單是否被 returned,以及 gender。
工作空間中已經載入 rms 套件。
本練習屬於課程
R 的行銷分析機器學習
練習說明
- 使用
cph()計算 Cox PH 模型。將shoppingCartValue、voucher、returned與gender納入為預測變數。請留意正確指定公式。將結果存為名為fitCPH的物件,並列印結果。 - 對
coefficients取指數以便解讀。在解讀時,請注意shoppingCartValue是連續變數,而其餘變數為類別變數。 - 繪製結果摘要。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Determine distributions of predictor variables
dd <- datadist(dataNextOrder)
options(datadist = "dd")
# Compute Cox PH Model and print results
___ <- ___(Surv(daysSinceFirstPurch, boughtAgain) ___ shoppingCartValue ___ voucher ___ returned ___ gender,
data = ___,
x = TRUE, y = TRUE, surv = TRUE)
print(___)
# Interpret coefficients
___(fitCPH$___)
# Plot result summary
___(___(fitCPH), log = TRUE)