plot_-forest命令给出了以下错误:用于定义子组的变量不是分类的
我试图为不同的子组(变量)按女性变量分层的Cox回归做森林图。 我使用了以下代码plot_-forest命令给出了以下错误:用于定义子组的变量不是分类的,r,plot,cox-regression,forestplot,R,Plot,Cox Regression,Forestplot,我试图为不同的子组(变量)按女性变量分层的Cox回归做森林图。 我使用了以下代码 library(SubgrPlots) dat<-subset(data, select=c( "comp2_years","comp2", "FEMALE", "Age75yoryears","Diabetes","MI", "LVEF_pre","offpu
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 , "No", "Yes")),
MI = factor(ifelse(MI == 0 , "No", "Yes")),
LVEF_pre = factor(ifelse(LVEF_pre == 0 , "No", "Yes")),
offpump = factor(ifelse(offpump == 0 , "No", "Yes")),
MAG = factor(ifelse(MAG == 0 , "No", "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, 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"))
如有任何建议,将不胜感激
> 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 ... ```