分层cox模型图与R

分层cox模型图与R,r,plot,cox,R,Plot,Cox,我正在查看R中的bfeed数据集: library(survival) library(KMsurv) data(bfeed) dput(head(bfeed)) structure(list(duration = c(16L, 1L, 4L, 3L, 36L, 36L), delta = c(1L, 1L, 0L, 1L, 1L, 1L), race = c(1L, 1L, 1L, 1L, 1L, 1L), poverty = c(0L, 0L, 0L, 0L, 0L, 0L), smok

我正在查看R中的bfeed数据集:

library(survival)
library(KMsurv)
data(bfeed)
dput(head(bfeed))
structure(list(duration = c(16L, 1L, 4L, 3L, 36L, 36L), delta = c(1L, 
1L, 0L, 1L, 1L, 1L), race = c(1L, 1L, 1L, 1L, 1L, 1L), poverty = c(0L, 
0L, 0L, 0L, 0L, 0L), smoke = c(0L, 1L, 0L, 1L, 1L, 0L), alcohol = c(1L, 
0L, 0L, 1L, 0L, 0L), agemth = c(24L, 26L, 25L, 21L, 22L, 18L), 
    ybirth = c(82L, 85L, 85L, 85L, 82L, 82L), yschool = c(14L, 
    12L, 12L, 9L, 12L, 11L), pc3mth = c(0L, 0L, 0L, 0L, 0L, 0L
    )), row.names = c(NA, 6L), class = "data.frame")
我为此制作了三个模型:

bf.surv <- Surv(duration,delta)
racef <- factor(race, labels = c("white","black","other"))
bf.moda <- aareg(bf.surv~smoke*alcohol+racef+poverty)
bf.mod1 <- coxph(bf.surv~smoke*alcohol+racef+poverty)
bf.mod2 <- coxph(bf.surv~strata(smoke)+strata(alcohol)+racef+poverty)

bf.surv
basehaz
?按
r
标记(悬停或单击查看):指定所有带有
library()
调用的非基本包。我不明白您的评论?bfeed数据来自KMSurv包,这就是您要问的吗?基本上,如果我们复制并粘贴您的代码,就像在一个空的R环境中一样,它是否可以运行和复制?很可能在
basehaz未找到时出错
。试试看。我们需要所有的
行。快速查找表示
库(生存)
。请什么都不要假设。无需指定基本R包:
base
stats
graphics
,等等。
exp(coef(fit))
是相对风险估计,而不是预测生存率,
basehaz(fit)
是,因此它们是非公度量表上的值@冻糕是对的;但是你也应该包括
library(survival)
以及
library(KMsurv)
好的,我指定的更好,谢谢。我还在学习如何提问,对不起!
bf.new <- data.frame(rbind(c(smoke=0,alcohol=0),c(smoke=1,alcohol=0),c(smoke=0,alcohol=1),c(smoke=1,alcohol=1)),poverty=0,racef="white")
bf.fit <- survfit(bf.mod1,bf.new)
t <- c(0,bf.moda$times) # ties
temp <- rbind(0,bf.moda$coef)
temp.beta <- rowsum(temp,t,reorder=F)
Beta <- apply(temp.beta,2,cumsum)
T.s <- unique(t)

plot(T.s, exp(-Beta[,1]), type="s", xlab="Time", ylab="Estimated Survival Fuction", main="Comparing Models - No smoking, No Alcohol")
lines(bf.fit[1], type="s", col=2, conf.int=FALSE)
bf.bh   <- basehaz(bf.mod2)
cond1   <- bf.bh$strata=="smoke=0,alcohol=0"
mod2.t1 <- bf.bh$time[cond1]
mod2.s1 <- bf.bh$hazard[cond1]

plot(T.s, exp(-Beta[,1]), type="s", xlab="Time", ylab="Estimated Survival Fuction", main="Comparing Models - No smoking, No Alcohol")
lines(bf.fit[1], type="s", col=2, conf.int=FALSE)
lines(mod2.t1,mod2.s1, type="s", col=3, conf.int=FALSE)