我正在尝试使用生存分析来分析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)
是什么意思?
感谢您的帮助。
答案 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
}
cph
和coxph
两者给出与系数相同的结果:
>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"