gpt4 book ai didi

R - 从 Survfit with Strata 中提取汇总表

转载 作者:行者123 更新时间:2023-12-04 10:45:37 26 4
gpt4 key购买 nike

我是 R 和生存分析的新手,我有兴趣将 survfit 的结果导出到数据框中,其中有层。

该站点提供了一个很好的解决方案,但不是针对分层的 (https://stat.ethz.ch/pipermail/r-help/2014-October/422348.html)。我如何使用包含层类型的额外列附加(或堆叠)每个层。
提供的链接中的解决方案不适用于分层分组

library(survival)
data(lung)
mod <- with(lung, survfit(Surv(time, status)~ 1))
res <- summary(mod)
str(res)

# Extract the columns you want
cols <- lapply(c(2:6, 8:10) , function(x) res[x])
# Combine the columns into a data frame
tbl <- do.call(data.frame, cols)
str(tbl)

先谢谢你,
R新手

最佳答案

它与您在那里的基本相同,只是额外的一列

res <- summary( survfit( Surv(futime, fustat)~rx, data=ovarian))
cols <- lapply(c(2:6, 8:11) , function(x) res[x])
tbl <- do.call(data.frame, cols)
head(tbl)
# time n.risk n.event n.censor surv strata std.err upper lower
# 1 59 13 1 0 0.9230769 rx=1 0.0739053 1.0000000 0.7890186
# 2 115 12 1 0 0.8461538 rx=1 0.1000683 1.0000000 0.6710952
# 3 156 11 1 0 0.7692308 rx=1 0.1168545 1.0000000 0.5711496
# 4 268 10 1 0 0.6923077 rx=1 0.1280077 0.9946869 0.4818501
# 5 329 9 1 0 0.6153846 rx=1 0.1349320 0.9457687 0.4004132
# 6 431 8 1 0 0.5384615 rx=1 0.1382642 0.8906828 0.3255265

关于R - 从 Survfit with Strata 中提取汇总表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31198584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com