我有一个关于样条图“居中”的问题。 当危险比= 1时,plotHR取哪个值? 例如,使用Coxph函数时是否可以将危险比1分配给中位年龄(或平均年龄)? 使用coxph函数和pspline时是否可以手动选择与y轴值危险比= 1相关联的x轴值(例如年龄)?
plotHR包含在Greg软件包中。 以下示例对该plotHR示例进行了稍微修改:https://rdrr.io/cran/Greg/man/plotHR.html
下面的代码会将危险比1分配给中间年龄与第三四分位数之间的某个x轴值。如何分配年龄与危险的中位数为1?
library(Greg)
library(survival)
library(rms)
# Get data for example
n <- 1000
set.seed(731)
age <- c(rnorm(50, mean=20, sd=1), round(50 + 12*rnorm(900), 1),rnorm(50, mean=80, sd=1))
label(age) <- "Age"
sex <- factor(sample(c('Male','Female'), n,
rep=TRUE, prob=c(.6, .4)))
cens <- c(17*runif(n-60),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
smoking <- factor(sample(c('Yes','No'), n,
rep=TRUE, prob=c(.2, .75)))
h <- .02*exp(.02*(age-50)+.1*((age-50)/10)^3+.8*(sex=='Female')+2*(smoking=='Yes'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
# Add missing data to smoking
smoking[sample(1:n, round(n*0.05))] <- NA
# Create a data frame since plotHR will otherwise
# have a hard time getting the names of the variables
ds <- data.frame(
dt = dt,e = e,
age=age,
smoking=smoking,
sex=sex)
library(splines)
Srv <- Surv(dt,e)
org_par <- par(xaxs="i", ask=TRUE)
dd <- datadist(ds)
options(datadist='dd')
fit.cph <- coxph(Srv ~ pspline(age,4) + sex + smoking, data=ds, x=TRUE, y=TRUE)
unadjusted_fit <- coxph(Srv ~ pspline(age,4), data=ds, x=TRUE, y=TRUE)
plotHR(list(fit.cph, unadjusted_fit), term="age", xlab="Age",
polygon_ci=c(TRUE, FALSE),
col.term = c("#08519C", "#77777799"),
col.se = c("#DEEBF7BB", grey(0.6)),
lty.term = c(1, 2),
plot.bty="l", xlim=c(30, 90),rug="ticks")
par(org_par)
上面代码的结果如下图(手动添加了红色框,以显示HR = 1中位年龄未分配给对方): Resulting Spline-Plot