从 R 中的 coxph 对象进行预测时与 predict.coxph vs predict 的区别

问题描述 投票:0回答:0

在包开发过程中,我遇到了 R 中生存包中的“predict.coxph”函数的特殊性。看起来“predict.coxph”没有从生存包中导出,所以调用它我必须使用'survival:::predict.coxph'(注意三重':::')。很长一段时间以来,我一直在使用统计包中的“predict”而不是“predict.coxph”,这让我开始思考两者的含义。

stats 中的“predict”函数必须计算出该对象是一个 coxph 对象,因此生成适当的线性预测器,但在“predict”的文档页面上没有提到使用“predict.coxph'.

问题1),它是怎么做到的?它是以某种方式从生存包中找到'predict.coxph',还是完全分开?

predict.coxph”没有从生存包中导出,这看起来很奇怪,因为它会被广泛使用。

问题2)为什么没有导出predict.coxph?使用'survival:::predict.coxph'是个坏主意吗?

这很有趣,因为在开发依赖于“predict.coxph”的包时,我收到有关使用“::”的警告消息,因此计划改用“predict”,但我想完全理解它是如何工作的。

下面的可重现代码。请注意,coxph.pred1 和 coxph.pred4 给出相同的答案,coxph.pred2 和 coxph.pred3 找不到函数。

library(survival)

### Load data
myeloma <- myeloma

### Add predictor
myeloma$x1 <- rnorm(nrow(myeloma), 0, 1)

### Fit cox proportional hazards
coxph.obj <- coxph(Surv(futime, death) ~ x1, data = myeloma)

### Check model output
summary(coxph.obj)

### Create predictions for individuals in myeloma dataset
coxph.pred1 <- predict(coxph.obj, type = "lp")
coxph.pred2 <- predict.coxph(coxph.obj, type = "lp")
coxph.pred3 <- survival::predict.coxph(coxph.obj, type = "lp")
coxph.pred4 <- survival:::predict.coxph(coxph.obj, type = "lp")

### Print how many elements are not the same in coxph.pred1 and coxph.pred4
sum(coxph.pred1 != coxph.pred4)
r predict cox-regression
© www.soinside.com 2019 - 2024. All rights reserved.