1

以下示例通过添加“年龄”从文档示例修改

d.coxph <- (survfit(Surv(time, status) ~ sex+age, data = lung))
autoplot(d.coxph)

我会收到以下错误:

levels<-( , value = if (nl == nL) as.character *tmp*(labels) else paste0(labels, : 因子级别 [41] 重复

输入帧号,或 0 退出

1: autoplot(d.coxph)> Error in levels<-( *tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [41] is duplicated

输入帧号,或 0 退出

1: autoplot(d.coxph) 2: autoplot.survfit(d.coxph) 3: 强化(object, surv.connect = surv.connect, fun = fun) 4: fortify.survfit(object, surv.connect = surv.连接,乐趣 = 乐趣)5:因子(代表(组 ID,模型 $strata),级别 = 组 ID)

2: autoplot.survfit(d.coxph) 3: 强化(对象, surv.connect = surv.connect, fun = fun) 4: fortify.survfit(object, surv.connect = surv.connect, fun = fun) 5:因子(rep(groupIDs,model$strata),levels = groupIDs)

4

1 回答 1

3

一种可能的解决方案是将连续变量age分类,并在 survfit 公式中考虑性别和年龄之间的交互作用:

library(survival)
data(lung)
lung$age2cat <- cut(lung$age,breaks=2)
lung$sex <- factor(lung$sex, labels=c("F","M"))
d.coxph <- survfit(Surv(time, status) ~ interaction(sex,age2cat), data = lung)

autoplot(d.coxph, conf.int=F, surv.size=1)

在此处输入图像描述

于 2018-05-01T09:49:32.707 回答