尝试在 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)