我是 R 新手。目前,我正在将对数正态分布拟合到我拥有的一些生存数据中,但是在尝试计算中位数和平均值等统计数据时,我陷入了困境。这是我到目前为止使用过的代码,谁能告诉我接下来应该输入什么来找到平均值?
# rm(list=ls(all=TRUE))
library(survival)
data<-read.table("M:\\w2k\\Diss\\Hoyle And Henley True IPD with number at risk known.txt",header=T)
attach(data)
data
times_start <-c( rep(start_time_censor, n_censors), rep(start_time_event, n_events) )
times_end <-c( rep(end_time_censor, n_censors), rep(end_time_event, n_events) )
model <- survreg(Surv(times_start, times_end, type="interval2")~1, dist="lognormal")
intercept <- summary(model)$table[1]
log_scale <- summary(model)$table[2]
这就是我陷入困境的地方,我已经尝试过了:
meantime<-exp(intercept+log_scale/2)
但这似乎并没有给出一个现实的意思。
最佳答案
寻找有效示例的地方是?predict.survreg
。 (一般来说,使用预测
方法的帮助系统对于任何回归方法都是一种有效的策略。)
运行最后一个示例将为您提供足够的基础来继续。特别是,您应该看到回归系数不是生存时间或分位数的估计。
lfit <- survreg(Surv(time, status) ~ ph.ecog, data=lung)
pct <- 1:98/100 # The 100th percentile of predicted survival is at +infinity
ptime <- predict(lfit, newdata=data.frame(ph.ecog=2), type='quantile',
p=pct, se=TRUE)
matplot(cbind(ptime$fit, ptime$fit + 2*ptime$se.fit,
ptime$fit - 2*ptime$se.fit)/30.5, 1-pct,
xlab="Months", ylab="Survival", type='l', lty=c(1,2,2), col=1)
# The plot should be examined since you asked for a median survival time
abline(h= 0.5)
# You can drop a vertical from the intersection to get that graphically
...或...
str(ptime)
List of 2
$ fit : num [1:98] 9.77 16.35 22.13 27.46 32.49 ...
$ se.fit: num [1:98] 2.39 3.53 4.42 5.16 5.82 ...
您可以使用以下方法从生存时间序列中提取第 50 个百分位:
ptime$fit[which((1-pct)==0.5)]
# [1] 221.6023
以天为单位,这就是为什么 Therneau 除以 30.5 来显示月份
关于r - 在 R 中求生存分析中对数正态分布的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18813751/