-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path多基因预后模型
59 lines (49 loc) · 2.58 KB
/
多基因预后模型
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
50
51
52
53
54
55
56
57
58
59
cox=coxph(Surv(futime, fustat)~.,data =rt)
multiCox =cox
multiCox <- step(multiCox,direction ="both")
multiCoxSum <- summary(multiCox)
out_multi <- data.frame()
out_multi <- cbind(
coef=multiCoxSum$coefficients[,"coef"],
HR=multiCoxSum$conf.int[,"exp(coef)"],
HR.95L=multiCoxSum$conf.int[,"lower .95"],
HR.95H=multiCoxSum$conf.int[,"upper .95"],
pvalue=multiCoxSum$coefficients[,"Pr(>|z|)"])
out_multi <- as.data.frame(cbind(id=row.names(out_multi),out_multi))
omulti<-filter(out_multi,pvalue<0.05)
omulti
# 森林图
out_multi[,2:ncol(out_multi)] <- as.numeric(unlist(out_multi[,2:ncol(out_multi)]))
hz <- paste(round(out_multi$HR,3),
"(",round(out_multi$HR.95L,3),
"-",round(out_multi$HR.95H,3),")",sep = "")
tabletext <- cbind(c(NA,"Gene",out_multi$id),
c(NA,"Coefficient",round(out_multi$coef,3)),
c(NA,"P value",ifelse(out_multi$pvalue<0.001,"P < 0.001",round(out_multi$pvalue,3))),
c(NA,"Hazard Ratio(95% CI)",hz))
library(forestplot)
forestplot(labeltext=tabletext,
graph.pos=3, #为Pvalue箱线图所在的位置
col=fpColors(box="#D55E00", lines="#CC79A7", zero = "gray50"),
mean=c(NA,NA,out_multi$HR),
lower=c(NA,NA,out_multi$HR.95L), #95%置信区间下限
upper=c(NA,NA,out_multi$HR.95H), #95%置信区间上限
boxsize=0.3,lwd.ci=2, #箱子大小,线的宽度
ci.vertices.height = 0.08,ci.vertices=TRUE, #置信区间用线宽、高、型
zero=1,lwd.zero=1, #zero线宽 基准线的位置
colgap=unit(5,"mm"), #列间隙
xticks = c(0.5, 1,1.5), #横坐标刻度
lwd.xaxis=1, #X轴线宽
lineheight = unit(0.8,"cm"), #固定行高
graphwidth = unit(.3,"npc"), #图在表中的宽度比例
cex=0.9, fn.ci_norm = fpDrawCircleCI, #误差条显示方式
hrzl_lines=list("2" = gpar(lwd=2, col="black"),
"3" = gpar(lwd=2, col="black"), #第三行顶部加黑线,引号内数字标记行位置
"16" = gpar(lwd=2, col="black")),#最后一行底部加黑线,"16"中数字为nrow(tabletext)+1
mar=unit(rep(0.5, times = 4), "cm"),#图形页边距
#fpTxtGp函数中的cex参数设置各个组件的大小
txt_gp=fpTxtGp(label=gpar(cex=1),
ticks=gpar(cex=1.5),
xlab=gpar(cex = 1.25),
title=gpar(cex = 1.2)),
xlab="Hazard Ratio")