簡體   English   中英

將文本添加到受限三次樣條曲線圖

[英]Addnig text to restricted cubic splines plot

我有以下假設數據來繪制受限三次樣條曲線

library(rms)
library(survival)
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('Male','Female'), n, rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)

f <- cph(S ~ rcs(age,4) + sex, x=TRUE, y=TRUE)
cox.zph(f, "rank")             # tests of PH
anova(f)
plot(Predict(f, age, sex)) # plot age effect, 2 curves for 2 sexes

弄清楚上面的數據,我得到了這個精細的圖: 在此處輸入圖片說明

我想向其添加以下文本text(60,-1,"p < 0.001")但是它不起作用,並給我以下錯誤消息: plot.new has not been called yet 有什么想法可能是問題嗎? 還有其他方法可以向其中添加文本(或圖例)嗎?

rms軟件包移至點陣繪圖平台。 您將需要在面板調用或補充晶格功能之一中添加文本。 請參閱?llines或使用trellis.focus

[![ap <- function(...) { ltext(60, 1, "p < 0.001") }

plot(Predict(f, age, sex), addpanel=ap)][1]][1]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM