library(survival)
> dput(kmsurvival)
structure(list(n = c(9L, 12L), time = c(28, 34, 38, 43, 44, 47,
48, 54, 29, 39, 41, 47, 48, 49, 52, 53, 54, 58, 63), n.risk = c(9,
8, 7, 6, 5, 4, 3, 1, 12, 11, 10, 9, 8, 7, 6, 4, 3, 2, 1), n.event = c(1,
1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1), n.censor = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), surv = c(0.888888888888889,
0.777777777777778, 0.666666666666667, 0.555555555555555, 0.444444444444444,
0.333333333333333, 0.111111111111111, 0, 0.916666666666667, 0.833333333333333,
0.75, 0.666666666666667, 0.583333333333333, 0.5, 0.333333333333333,
0.25, 0.166666666666667, 0.0833333333333333, 0), type = "right",
strata = structure(c(8L, 11L), .Names = c("Type=BRCA1", "Type=BRCA2"
)), std.err = c(0.117851130197758, 0.17817416127495, 0.235702260395516,
0.298142396999972, 0.372677996249965, 0.471404520791032,
0.942809041582063, Inf, 0.0870388279778489, 0.129099444873581,
0.166666666666667, 0.204124145231932, 0.243975018237133,
0.288675134594813, 0.408248290463863, 0.5, 0.645497224367903,
0.957427107756338, Inf), upper = c(1, 1, 1, 0.996567599682496,
0.922659733015886, 0.839728708174735, 0.70514430333281, NA,
1, 1, 1, 0.994625360259091, 0.940998012173809, 0.880421672024074,
0.741959705452895, 0.666102065388224, 0.590604814783314,
0.544229633514318, NA), lower = c(0.705557501515943, 0.548521190012713,
0.420028358578948, 0.309705006872564, 0.214088528120615,
0.132317866507894, 0.0175080177972009, NA, 0.772900973689615,
0.647036987013362, 0.540996355616556, 0.446846081150264,
0.361613705210385, 0.283954845665321, 0.149753565179511,
0.0938294643532942, 0.0470327655353929, 0.0127601365614755,
NA), conf.type = "log", conf.int = 0.95, call = survfit(formula = Surv(Time) ~
Type, data = data2)), .Names = c("n", "time", "n.risk",
"n.event", "n.censor", "surv", "type", "strata", "std.err", "upper",
"lower", "conf.type", "conf.int", "call"), class = "survfit")
> plot(kmsurvival, fun = function(x) 1 - x, col = c("black", "red"), xlab = "Time",
+ ylab = "Cumulative Probability", main = "Cumulative Incidence", conf = FALSE)
> legend(0, 0.25, c("A", "B"), col = c("black", "red"), lty = c(1, 1))
我有一个累积发病率图,我想知道两个曲线(A和B)在时间= 20,30,40,50和60时的累积概率是多少,并标记这10个点。
答案 0 :(得分:2)
我无法使用您的数据,因为缺少data2
,但这里有一条类似的曲线。有关曲线的所有信息都包含在模型中。因此,您可以提取在特定时间标记点所需的内容。
## Make a similar fit
require(survival)
library(OIsurv) # only needed for tongue data
data(tongue)
kmsurvival <- with(tongue, survfit(Surv(time) ~ type))
## Extract data from model
dat <- with(summary(kmsurvival),
data.frame(surv=surv, type=as.integer(factor(strata)), time=time))
## Show points at these times
times <- with(dat, intersect(time[type==1], time[type==2]))
inds <- dat$time %in% times
## Make plot
plot(kmsurvival, fun = function(x) 1 - x, col = c("black", "red"), xlab = "Time",
ylab = "Cumulative Probability", main = "Cumulative Incidence", conf = FALSE)
legend("topleft", 0.25, c("A", "B"), col = c("black", "red"), lty = c(1, 1))
## Add points/labels at times
with(dat, {
points(time[inds], 1-surv[inds], col=type[inds], pch=16)
inds1 <- inds & type==1 # points on first curve
text(time[inds1], 1-surv[inds1], labels=round(1-surv[inds1], 2), adj=-0.5,
col=type[inds1])
inds2 <- inds & type==2 # points on second
text(time[inds2], 1-surv[inds2], labels=round(1-surv[inds2], 2), adj=1.5,
col=type[inds2])
})