如何从survfit函数中获取概率数据?

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

我根据

survival::survfit()
函数的数据绘制累积发生率曲线。在这个小插图之后,我做了如下的事情:

library(survival)
mgus2$etime <- with(mgus2, ifelse(pstat==0, futime, ptime))
event <- with(mgus2, ifelse(pstat==0, 2*death, 1))
mgus2$event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))
mfit2 <- survfit(Surv(etime, event) ~ sex, data=mgus2)
plot(mfit2)

four groups

数据有两个可能的事件(pcm 和死亡),包含的协变量性别有两个水平(男性和女性)。因此,正如预期的那样,结果图描绘了四条线的概率(我省略了标签,因为它们在这里并不重要)。

但是如何提取这些数据呢?我查看了

mfit2
内部的各个地方,但找不到创建绘图所需的数据。 x 轴有
mfit2$time
,但
mfit2$pstate
不包括所有四种概率(pcm 女性、pcm 男性、死亡女性和死亡男性)。
mfit2
中那些概率隐藏在哪里?

我找到了this答案,它建议了一些解决方法来获取数据。我发现解决方法有效,这不是问题。

mfit2
内的绘图数据在哪里?它一定在某个地方,因为
plot(mfit2)
返回了我们期望的情节。

r list plot survival-analysis survival
1个回答
0
投票

您正在寻找

$pstate
,其中包含两个级别 sex
串联
概率(女性是第一级)。

levels(mgus$sex)
#[1] "female" "male" 

mfit2$pstate
(和
mfits$time
)的长度是454,前227对应于女性的概率。

plot(mfit2)
lines(mfit2$time[1:227], mfit2$pstate[1:227, 2], type="s", col="red")
lines(mfit2$time[228:454], mfit2$pstate[228:454, 2], type="s", col="red")
lines(mfit2$time[1:227], mfit2$pstate[1:227, 3], type="s", col="green")
lines(mfit2$time[228:454], mfit2$pstate[228:454, 3], type="s", col="green")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.