【发布时间】:2024-01-21 17:26:01
【问题描述】:
尝试在 survplot 中沿 x 轴绘制处于危险中的对象时收到以下错误消息:
Error in text.default(tt[-1], yy, nri[-1], cex = cex.n.risk, adj = 1) : zero-length 'labels' specified
有什么帮助吗?我对生存分析相当陌生,未能找到对此错误的任何解释。 总体而言,代码看起来不错,除非我为绘图添加 n.risk=TRUE 选项,否则会出现错误。任何提示将不胜感激。非常感谢。
下面的数据以及使用的代码。
数据在这里
Duration <- structure(list(conflict = c("Angola 75-89", "Angola 89-91", "Angola 92-94",
"Azerb (N-K) 89-94", "Bosnia 92-95", "Cambodia 70-91", "Chad 79-79",
"Chad 89-96", "Chechnya 94-96", "Colombia 48-57", "Croatia 91-91 (?)",
"Croatia 95-95", "DomRep 65-65", "El Salv 79-91", "GeorgA 89-92",
"GeorgB 92-94", "Guatem 68-96", "India 46-48", "Iraq 61-70",
"Laos 59-73", "Lebanon 58-58", "Lebanon 75-89", "Liberia 89-93",
"Malaysia 48-56", "Moldova 92-92", "Mozamb 81-92", "Nicara 81-89",
"Phil 72-96", "Rwanda 90-93", "SieLeo 91-96", "Stafrica 83-91",
"Sudan 63-72", "Tajik 92-97", "Yemen 62-70", "Zimbab 72-79",
"Guinea-Bissau June - November 1998", "Liberia 94-96", "Papua New Guinea 1990 - 2001",
"Afghanistan 1978 - 2001", "Ethiopia 1961-1993", "Indonesia (Aceh) 1976 - 2005",
"Kenya 2007- 2008", "Nepal 1996 - 2006", "Somalia 1991 - 2008",
"Bangladesh 1997", "Burundi 1993-2005", "Cote d'Ivoire 2002-2007",
"Democratic Republic of Congo 98-03", "Northern Ireland (68-98)",
"Darfur, Sudan 2003-2010", "Sudan 83-05", "Liberia 1999-2003"
), peacedur = c(2, 17, 58, 175, 157, 206, 7, 117, 34, 322, 43,
157, 520, 204, 192, 171, 144, 0.100000001490116, 48, 25, 199,
230, 12, 626, 89, 195, 232, 148, 8, 6, 204, 141, 138, 357, 348,
122, 40, 23, 0.100000001490116, 60, 40, 8, 24, 0.100000001490116,
133, 28, 22, 69, 128.5, 3, 71, 83), peacefail = c(1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0,
0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0,
0, 1, 0, 1, 1, 0), totalps = c(0L, 2L, 3L, 2L, 3L, 2L, 1L, 2L,
4L, 2L, 1L, 1L, 1L, 3L, 2L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 1L, 2L,
3L, 3L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 4L, 3L, 2L, 1L, 1L, 2L, 2L,
4L, 1L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 4L, 3L, 3L), year_end = c(1989L,
1991L, 1994L, 1994L, 1995L, 1991L, 1979L, 1996L, 1996L, 1957L,
1991L, 1995L, 1965L, 1991L, 1992L, 1994L, 1996L, 1948L, 1970L,
1973L, 1958L, 1989L, 1993L, 1956L, 1992L, 1992L, 1989L, 1996L,
1993L, 1996L, 1991L, 1972L, 1997L, 1970L, 1979L, 1998L, 1996L,
2001L, 2001L, 1993L, 2005L, 2008L, 2006L, 2008L, 1997L, 2005L,
2007L, 2003L, 1998L, 2010L, 2005L, 2003L), peacedur.year = c(1,
2, 5, 15, 14, 18, 1, 10, 3, 27, 4, 14, 44, 17, 16, 15, 12, 1,
4, 3, 17, 20, 1, 53, 8, 17, 20, 13, 1, 1, 17, 12, 12, 30, 29,
11, 4, 2, 1, 5, 4, 1, 2, 1, 12, 3, 2, 6, 11, 1, 6, 7), SurvObj = structure(c(2,
17, 58, 175, 157, 206, 7, 117, 34, 322, 43, 157, 520, 204, 192,
171, 144, 0.100000001490116, 48, 25, 199, 230, 12, 626, 89, 195,
232, 148, 8, 6, 204, 141, 138, 357, 348, 122, 40, 23, 0.100000001490116,
60, 40, 8, 24, 0.100000001490116, 133, 28, 22, 69, 128.5, 3,
71, 83, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1,
1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1,
1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0), .Dim = c(52L, 2L), .Dimnames = list(
NULL, c("time", "status")), type = "right", class = "Surv")), .Names = c("conflict",
"peacedur", "peacefail", "totalps", "year_end", "peacedur.year",
"SurvObj"), row.names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "51", "52",
"53"), class = "data.frame")
生存对象的创建
library(survival)
library(rms)
Duration$SurvObj <- with(Duration, Surv(peacedur, peacefail==1))
适合+转换成npsurv
KM.Duration.totalps <- survfit(SurvObj ~ totalps, data = Duration, conf.type = "log-log")
class(KM.Duration.totalps) <- c(class(KM.Duration.totalps), "npsurv")
剧情:
survplot(KM.Duration.totalps,
xlab="duration in months", ylab="survival prob",
conf="none",
label.curves = TRUE,
time.inc=12,
levels.only = FALSE,
n.risk=TRUE)
【问题讨论】:
-
totalps=0只有 1 个事件。n.risk不喜欢这样。运行survplot(KM.Duration.totalps[-1], ...)与设置 n.risk = FALSE 一样 -
解决了它。非常感谢
-
如果包含风险对象的表格未完全显示或与 x 轴的标签重叠怎么办?由于这是一个不同的问题,我提出了一个新请求:*.com/questions/24467314/…;再次感谢!
-
@rawr:由于您的评论有效地回答了 OP 的问题,我建议您发布一个答案以便可以接受。 :)
标签: r survival-analysis