Você está na página 1de 3

#####

Modelo de Cox - Exemplo Cancer de Laringe #######

laringe<-read.table("http://www.est.ufpr.br/~suely/sobrev/laringe.txt", h=T)
attach(laringe)
require(survival)
fit2<-coxph(Surv(tempos,cens)~factor(estagio), data=laringe,
x = T, method="breslow")
summary(fit2)
fit2$loglik
fit3<- coxph(Surv(tempos,cens)~factor(estagio)+ idade, data=laringe,
x = T, method="breslow")
summary(fit3)
fit3$loglik
fit4<-coxph(Surv(tempos,cens) ~ factor(estagio) + idade + factor(estagio)*idade
,
data=laringe, x = T, method="breslow")
summary(fit4)
fit4$loglik
residuals.coxph(fit4,type="scaledsch")
cox.zph(fit4)
par(mfrow=c(2,4))
plot(cox.zph(fit4))
residuals.coxph(fit3,type="scaledsch")
cox.zph(fit3)
par(mfrow=c(1,4))
plot(cox.zph(fit3))
ss<-survfit(fit4)
round(ss$surv,digits=5)
# S(t|x) para x = xbar (default R) #
b<-fit4$coefficients
b<-as.vector(b)
x<- fit4$x
xbar<-as.matrix(apply(x,2,mean))
embx<-exp(-sum(b*xbar))
s0<-(ss$surv)^embx
H0<- -log(s0)
x1<-as.matrix(H0)
n<-nrow(x1)
a0<-rep(0,n)
for(i in 1:n){a0[i]<-H0[i+1] - H0[i]}
lambda0<-c(H0[1],a0[1:(n-1)])
lambda0<-c(H0[1],a0[1:(n-1)])
round(cbind(ss$time,s0,lambda0,H0),digits=5)
basehaz(fit4,centered=F)
do base (compare!)

# Obs: funcao basehaz tambem fornece o risco acumula

tt<-sort(tempos)
aux1<-as.matrix(tt)
n<-nrow(aux1)
aux2<-as.matrix(cbind(ss$time,s0))
S00<-rep(max(aux2[,2]),n)
s0
for(i in 1:n){
if(tt[i]> min(aux2[,1])){

i1<- aux2[,1]<= tt[i]


S00[i]<-min(aux2[i1,2])}}
ts0<-cbind(tt,S00)
ts0
b<-fit4$coefficients
id<-50
st1<- S00^(exp(b[4]*id)) # S(t|x) para estgio I e idade = 50 anos #
st2<- S00^( exp(b[1]+( ( b[4]+b[5] )*id) ) ) # S(t|x) para estgio II e idade = 5
0 anos #
st3<- S00^( exp(b[2]+( ( b[4]+b[6] )*id) ) ) # S(t|x) para estgio III e idade =
50 anos #
st4<- S00^( exp(b[3]+( ( b[4]+b[7] )*id) ) ) # S(t|x) para estgio IV e idade = 5
0 anos #
id<- 65
st11<- S00^(exp(b[4]*id)) # S(t|x) para estgio I e idade = 65 anos #
st21<- S00^( exp(b[1]+( ( b[4]+b[5] )*id) ) ) # S(t|x) para estgio II e idade =
65 anos #
st31<- S00^( exp(b[2]+( ( b[4]+b[6] )*id) ) ) # S(t|x) para estgio III e idade =
65 anos #
st41<- S00^( exp(b[3]+( ( b[4]+b[7] )*id) ) ) # S(t|x) para estgio IV e idade =
65 anos #
par(mfrow=c(1,2))
plot(tt,st1,type="s",ylim=range(c(0,1)),xlab="Tempos",ylab="S(t|x)",lty=1)
lines(tt,st2,type="s",lty=2)
lines(tt,st3,type="s",lty=3)
lines(tt,st4,type="s",lty=4)
legend(0,0.2,lty=c(1,2,3,4),c("estgio I","estgio II","estgio III","estgio IV"),lwd=
1,bty="n",cex=0.7)
title(" Idade = 50 anos")
plot(tt,st11,type="s",ylim=range(c(0,1)),xlab="Tempos",ylab="S(t|x)",lty=1)
lines(tt,st21,type="s",lty=2)
lines(tt,st31,type="s",lty=3)
lines(tt,st41,type="s",lty=4)
legend(0,0.2,lty=c(1,2,3,4),c("estgio I","estgio II","estgio III","estgio IV"),lwd=
1,bty="n",cex=0.7)
title(" Idade = 65 anos")

tt<-sort(tempos)
aux1<-as.matrix(tt)
n<-nrow(aux1)
aux2<-as.matrix(cbind(ss$time,lambda0))
lambda00<-rep(min(aux2[,2]),n)
for(i in 1:n){
if(tt[i]> min(aux2[,1])){
i1<- aux2[,1]<= tt[i]
lambda00[i]<-max(aux2[i1,2])}
}
tlambda0<-cbind(tt,lambda00)
b<-fit4$coefficients
id<-50
rt1<- lambda00*(exp(b[4]*id)) # risco para estagio
rt2<- lambda00*( exp(b[1]+( ( b[4]+b[5] )*id) ) ) #
e = 50 anos #
rt3<- lambda00*( exp(b[2]+( ( b[4]+b[6] )*id) ) ) #
de = 50 anos #
rt4<- lambda00*( exp(b[3]+( ( b[4]+b[7] )*id) ) ) #
e = 50 anos #
id<-65

I e idade = 50 anos #
risco para estagio II e idad
risco para estagio III e ida
risco para estagio IV e idad

rt11<- lambda00*(exp(b[4]*id)) # risco para estagio I e idade = 65 anos #


rt21<- lambda00*(exp(b[1]+( ( b[4]+b[5] )*id) ) ) # risco para estagio II e idad
e = 65 anos #
rt31<- lambda00*(exp(b[2]+( ( b[4]+b[6] )*id) ) ) # risco para estagio III e ida
de = 65 anos #
rt41<- lambda00*(exp(b[3]+( ( b[4]+b[7] )*id) ) ) # risco para estagio IV e idad
e = 65 anos #
par(mfrow=c(1,2))
plot(tt,rt1,type="s",ylim=range(c(0,0.5)),xlab="Tempos", ylab="Risco(t|x)", lty=
1)
lines(tt,rt2,type="s",lty=2)
lines(tt,rt3,type="s",lty=3)
lines(tt,rt4,type="s",lty=4)
legend(0,0.45, lty=c(1,2,3,4),c("estagio I","estagio II","estagio III","estagio
IV"),lwd=1,bty="n",cex=0.7)
title(" Idade = 50 anos")
plot(tt,rt11,type="s",ylim=range(c(0,0.5)),xlab="Tempos", ylab="Risco(t|x)", lty
=1)
lines(tt,rt21,type="s",lty=2)
lines(tt,rt31,type="s",lty=3)
lines(tt,rt41,type="s",lty=4)
legend(0,0.45, lty=c(1,2,3,4),c("estagio I","estagio II","estagio III","estagio
IV"),lwd=1,bty="n",cex=0.7)
title(" Idade = 65 anos")

Você também pode gostar