如何解决plot_forest 命令给了我这个错误:定义子组的变量不是分类的
我正在尝试为不同子组(变量)的 FEMALE 变量分层的 Cox 回归绘制森林图。 我使用了以下代码
library(SubgrPlots)
dat<-subset(data,select=c( "comp2_years","comp2","FEMALE","Age75yoryears","Diabetes","MI","LVEF_pre","offpump","MAG"))
dat$comp2<-as.numeric(dat$comp2)
#dat$comp2 = as.factor(dat$comp2)
dat$FEMALE = as.factor(dat$FEMALE)
str(dat)
dat = dat %>%
mutate(Age75yoryears = factor(ifelse(Age75yoryears == 0,"No","Yes")),Diabetes = factor(ifelse(Diabetes == 0,MI = factor(ifelse(MI == 0,LVEF_pre = factor(ifelse(LVEF_pre == 0,offpump = factor(ifelse(offpump == 0,MAG = factor(ifelse(MAG == 0,"Yes")) )
## Figure 1: Forest Plot ------------------------------------------------------
main.title = list("","Forest plot of subgroups","Kaplan-Meier curves\n by treatment group")
label.x = list("","hazard ratio","Time (days)")
plot_forest(dat,covari.sel = c(4,5,6,7,8,9),trt.sel = 3,# treatment code
resp.sel = c(1,2),# response variable
outcome.type = "survival",size.shape = c(0.3,6.5 / 4),font.size = c(1,1,.8),title = main.title,lab.x = label.x,time = 50,KM = T,show.km.axis =T,n.brk = 6,max.time = 70,widths = c(2,1.5,1),eff.scale = c("HR"))
但是,我收到以下错误:
plot_forest(dat,中的错误: 定义子组的变量不是分类的!
这是我的数据结构:
> str(dat)
tibble[,9] [13,803 x 9] (S3: tbl_df/tbl/data.frame)
$ comp2_years : num [1:13803] 10 10 10 10 9.77 ...
$ comp2 : Factor w/ 2 levels "0","1": 1 1 1 1 2 1 1 1 1 1 ...
$ FEMALE : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 2 1 1 1 ...
$ Age75yoryears: Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
$ Diabetes : Factor w/ 2 levels "No","Yes": 1 1 2 2 1 1 2 1 1 1 ...
$ MI : Factor w/ 2 levels "No","Yes": 1 1 1 1 2 1 1 1 1 1 ...
$ LVEF_pre : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
$ offpump : Factor w/ 2 levels "No","Yes": 2 2 2 2 2 2 2 2 2 2 ...
$ MAG : Factor w/ 2 levels "No","Yes": 1 2 2 1 2 2 2 1 2 1 ... ```
任何建议将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。