用于计算Cox比例风险模型的coxph和cph函数有什么区别?

时间:2013-12-23 11:35:37

标签: r rms

我正在尝试使用生存分析来分析R中包veteran中的数据集(survival)。我在包cph中找到了rms函数,它似乎与coxph不同。这两个功能有什么区别?

此外,在此示例中,

model1<-cph(with(data=veteran,Surv(time,status)~rcs(age,4)+trt),x=TRUE,y=TRUE)

rcs(age,4)是什么意思?

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

RCS =受限制的三次样条。 您可以通过查看help(package="rms")

找到该功能的帮助文件

以下是源代码的摘录,因此您可以看到cph函数调用coxph.fit函数的位置(coxph包中survival的胆量)< / p>


>cph

[...]
    if (nullmod) 
        f = NULL
    else {
        ytype = attr(Y, "type")
        fitter = if (method == "breslow" || method == "efron") {
            if (ytype == "right") 
                coxph.fit
            else if (ytype == "counting") 
                survival:::agreg.fit
            else stop(paste("Cox model doesn't support \"", ytype, 
                "\" survival data", sep = ""))
        }
        else if (method == "exact") 
            survival:::agexact.fit

[...]

    class(f) = c("cph", "rms", "coxph")
    f
}


cphcoxph两者给出与系数相同的结果:


>library("survival")
>library("rms")
>
>x = rbinom(100, 1,.5)
>t = rweibull(100, 1, 1)
>
>m1 = coxph(Surv(t)~x)
>m2 = cph(Surv(t)~x)
>m1$coefficients
        x 
0.2226732 
>m2$coefficients
        x 
0.2226732 

但是你可以看到cph函数的作者在结果中添加了一些额外的组件以满足他们的需要。因此,如果您需要其中一项额外功能,cph会很有用,但除此之外,coxph会很好。


>attributes(m1)
$names
 [1] "coefficients"      "var"               "loglik"            "score"            
 [5] "iter"              "linear.predictors" "residuals"         "means"            
 [9] "concordance"       "method"            "n"                 "nevent"           
[13] "terms"             "assign"            "wald.test"         "y"                
[17] "formula"           "call"             

$class
[1] "coxph"

>attributes(m2)
$names
 [1] "coefficients"      "var"               "loglik"            "score"            
 [5] "iter"              "linear.predictors" "residuals"         "means"            
 [9] "concordance"       "terms"             "n"                 "call"             
[13] "Design"            "assign"            "na.action"         "fail"             
[17] "non.slopes"        "stats"             "method"            "maxtime"          
[21] "time.inc"          "units"             "center"            "scale.pred"       

$class
[1] "cph"   "rms"   "coxph"