γ = 1/scale =1/0.902
α = exp(−(Intercept)γ)=exp(-(7.111)*γ)
> library(survival) > myfit=survreg(Surv(futime, fustat)~1 , ovarian, dist="weibull",scale=0) > summary(myfit) Call: survreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist = "weibull", scale = 0) Value Std. Error z p (Intercept) 7.111 0.293 24.292 2.36e-130 Log(scale) -0.103 0.254 -0.405 6.86e-01 Scale= 0.902 Weibull distribution Loglik(model)= -98 Loglik(intercept only)= -98 Number of Newton-Raphson Iterations: 5 n= 26
画生存函数图
d<- seq(0, 2000, length.out=10000) h<-1-pweibull(d,shape=1/0.902,scale=exp(7.111)) df<-data.frame(t=d,s=h) library(ggplot2) ggplot(df,aes(x=t,y=s))+ geom_line(colour="green")+ ggtitle("s(t) \n 生存函数")
1. Surv
Description
创建一个生存对象,通常用作模型公式中的响应变量。 参数匹配是此功能的特殊功能,请参阅下面的详细信息。
Surv(time, time2, event,
type=c('right', 'left', 'interval', 'counting', 'interval2', 'mstate'),
origin=0)
is.Surv(x)
Arguments
time
对于右删失数据,这是一个跟踪时间。对于区间数据,第一个参数是区间的开始时间。
event
状态指示,通常,0=活着,1=死亡。其他选择是TRUE/FALSE (TRUE = 死亡) or 1/2 (2=死亡)。对于区间删失数据,状态指示,0=右删失, 1=事件时间, 2=左删失, 3=区间删失.
右删失(Right Censoring):只知道实际寿命大于某数;
左删失(Left Censoring):只知道实际寿命小于某数;
区间删失(Interval Censoring):只知道实际寿命在一个时间区间内。
time2
区间删失区间的结束时间或仅对过程数据进行计数。
type
指定删失类型。 "right", "left", "counting", "interval", "interval2" or "mstate".
如果event变量是一个因子,假定type="mstate"。如果没有指定参数time2,type="right";如果指定参数time2,type="counting"
Surv使用示例
> str(lung) 'data.frame': 228 obs. of 10 variables: $ inst : num 3 3 3 5 1 12 7 11 1 7 ... $ time : num 306 455 1010 210 883 ... $ status : num 2 2 1 2 2 1 2 2 2 2 ... $ age : num 74 68 56 57 60 74 68 71 53 61 ... $ sex : num 1 1 1 1 1 1 2 2 1 1 ... $ ph.ecog : num 1 0 0 1 0 1 2 2 1 2 ... $ ph.karno : num 90 90 90 90 100 50 70 60 70 70 ... $ pat.karno: num 100 90 90 60 90 80 60 80 80 70 ... $ meal.cal : num 1175 1225 NA 1150 NA ... $ wt.loss : num NA 15 15 11 0 0 10 1 16 34 ... > with(lung, Surv(time, status)) [1] 306 455 1010+ 210 883 1022+ 310 361 218 [10] 166 170 654 728 71 567 144 613 707 [19] 61 88 301 81 624 371 394 520 574 [28] 118 390 12 473 26 533 107 53 122 [37] 814 965+ 93 731 460 153 433 145 583 [4