Presentation is loading. Please wait.

Presentation is loading. Please wait.

The parametric frailty model workshop

Similar presentations


Presentation on theme: "The parametric frailty model workshop"— Presentation transcript:

1 The parametric frailty model workshop
Luc Duchateau Ghent University, Belgium

2 Event times in clusters of varying size Many large clusters (1)
One level of clustering, but varying cluster size Example: Time to culling of heifer cows as a function of early somatic cell count

3 Parametric gamma frailty model Extension: Piecewise constant h(t)
Time to culling as function of SCC and herd as frailty term Take first constant baseline hazard

4 Time to culling: data setwd("c://docs//onderwijs//survival//Flames//");culling<-read.table('culling.csv',header=T,sep=";") culltime<-culling$timetocul*12/ logSCC<-culling$logSCC;herd<-as.factor(culling$herd);status<-culling$status n<-length(levels(as.factor(herd)));di<-aggregate(status,by=list(herd),FUN=sum)[,2];r<-sum(di)

5 Time to culling: constant baseline function
#parametric exponential covariate lnscc1 with exp(theta) likelihood.exp<-function(p){ cumhaz<-exp(logSCC*p[1])*exp(p[3])*culltime cumhaz<-aggregate(cumhaz,by=list(herd),FUN=sum)[,2] lnhaz<-status* (logSCC*p[1]+log(exp(p[3]))) lnhaz<-aggregate(lnhaz,by=list(herd),FUN=sum)[,2] lik<-r*log(exp(p[2]))-sum((di+1/exp(p[2]))*log(1+cumhaz*exp(p[2])))+sum(lnhaz)-n*log(gamma(1/exp(p[2])))+sum(log(gamma(di+1/exp(p[2])))) -lik }

6 Time to culling: constant baseline maximise function
initial<-c(0,log(0.2),log(0.01)); t<-nlm(likelihood.exp,initial,print.level=2) beta<-t$estimate[1];theta<-exp(t$estimate[2]);lambda<-exp(t$estimate[3]) beta;theta;lambda

7 Time to culling: constant baseline function for standard errors
likelihood.exp<-function(p){ cumhaz<-exp(logSCC*p[1])*p[3]*culltime cumhaz<-aggregate(cumhaz,by=list(herd),FUN=sum)[,2] lnhaz<-status* (logSCC*p[1]+log(p[3])) lnhaz<-aggregate(lnhaz,by=list(herd),FUN=sum)[,2] lik<-r*log(p[2])-sum((di+1/p[2])*log(1+cumhaz*p[2]))+sum(lnhaz)-n*log(gamma(1/p[2]))+sum(log(gamma(di+1/p[2]))) -lik } initial<-c(beta,theta,lambda);t<-nlm(likelihood.exp,initial,iterlim=1,hessian=T) beta<-t$estimate[1];theta<-t$estimate[2];lambda<-t$estimate[3] beta;theta;lambda stderr<-sqrt(diag(solve(t$hessian)));stderr

8 Parametric gamma frailty model Extension: Piecewise constant h(t)
Time to culling as function of SCC and herd as frailty term Take first constant baseline hazard

9 Parametric gamma frailty model Extension: Piecewise constant h(t)
Constant baseline hazard incorrect Use piecewise constant baseline hazard

10 Time to culling: PW constant baseline: function
endp1<-70*12/365.25;endp2<-300*12/ likelihood.piecexp<-function(p){ cumhaz<-exp(logSCC*p[1])*exp(p[3])*pmin(culltime,endp1) cumhaz<-cumhaz+exp(logSCC*p[1])*exp(p[4])*pmax(0,pmin(endp2-endp1,culltime-endp1)) cumhaz<-cumhaz+exp(logSCC*p[1])*exp(p[5])*pmax(0,culltime-endp2) cumhaz<-aggregate(cumhaz,by=list(herd),FUN=sum)[,2] lnhaz<-status*(logSCC*p[1]+log(as.numeric(culltime<endp1)*exp(p[3])+as.numeric(endp1<=culltime)*as.numeric(culltime<endp2)*exp(p[4])+as.numeric(culltime>=endp2)*exp(p[5]))) lnhaz<-aggregate(lnhaz,by=list(herd),FUN=sum)[,2] lik<-r*log(exp(p[2]))-sum((di+1/exp(p[2]))*log(1+cumhaz*exp(p[2])))+sum(lnhaz)-n*log(gamma(1/exp(p[2])))+sum(log(gamma(di+1/exp(p[2])))) -lik } initial<-c(0,log(0.2),log(0.01),log(0.01),log(0.01)) t<-nlm(likelihood.piecexp,initial,print.level=2) beta<-t$estimate[1] theta<-exp(t$estimate[2]) lambda1<-exp(t$estimate[3]) lambda2<-exp(t$estimate[4]) lambda3<-exp(t$estimate[5]) beta theta lambda1 lambda2 lambda3

11 Time to culling: PW constant baseline: function execution
initial<-c(0,log(0.2),log(0.01),log(0.01),log(0.01)) t<-nlm(likelihood.piecexp,initial,print.level=2) beta<-t$estimate[1] theta<-exp(t$estimate[2]) lambda1<-exp(t$estimate[3]) lambda2<-exp(t$estimate[4]) lambda3<-exp(t$estimate[5]) beta;theta;lambda1;lambda2;lambda3

12 Time to culling: PW constant baseline: function execution
#parametric piecewise exponential covariate lnscc1, natural likelihood.piecexp<-function(p){ cumhaz<-exp(logSCC*p[1])*p[3]*pmin(culltime,endp1) cumhaz<-cumhaz+exp(logSCC*p[1])*p[4]*pmax(0,pmin(endp2-endp1,culltime-endp1)) cumhaz<-cumhaz+exp(logSCC*p[1])*p[5]*pmax(0,culltime-endp2) cumhaz<-aggregate(cumhaz,by=list(herd),FUN=sum)[,2] lnhaz<-status*(logSCC*p[1]+log(as.numeric(culltime<endp1)*p[3]+as.numeric(endp1<=culltime)*as.numeric(culltime<endp2)*p[4]+as.numeric(culltime>=endp2)*p[5])) lnhaz<-aggregate(lnhaz,by=list(herd),FUN=sum)[,2] lik<-r*log(p[2])-sum((di+1/p[2])*log(1+cumhaz*p[2]))+sum(lnhaz)-n*log(gamma(1/p[2]))+sum(log(gamma(di+1/p[2]))) -lik } initial<-c(beta,theta,lambda1,lambda2,lambda3) t<-nlm(likelihood.piecexp,initial,iterlim=1,hessian=T) beta<-t$estimate[1];theta<-t$estimate[2];lambda1<-t$estimate[3] lambda2<-t$estimate[4];lambda3<-t$estimate[5] beta;theta;lambda1;lambda2;lambda3 stderr<-sqrt(diag(solve(t$hessian)));stderr

13 Parametric gamma frailty model Extension: Piecewise constant h(t)
Constant baseline hazard incorrect Use piecewise constant baseline hazard

14 Parametric gamma frailty model Comparing PW vs constant
Constant vs piecewise constant model P<

15 Parametric gamma frailty model Extension: Recurrent events (1)
Recurrent asthma data, drug vs placebo Patient i has ni at risk periods Different timescales

16 Parametric gamma frailty model Extension: Recurrent events (2)
Models expressed in terms of conditional hazard and fitted using marginal lilkehood Calendar time model Weibull baseline hazard

17 Calendar time: R program Reading the data
setwd("c://docs//onderwijs//survival//Flames//notas//") w <- read.table("asthma.dat",head=T) di<-aggregate(w$st.w,by=list(w$id.w),FUN=sum)[,2];r<-sum(di);n<-length(di) trt<-aggregate(w$trt.w,by=list(w$id.w),FUN=min)[,2] begin<-12*w$start.w/365.25;end<-12*w$stop.w/ ptno<-w$id.w;status<-w$st.w;gap<-end-begin;fevent<-w$fevent

18 Calendar time: R program function
#Weibull-calendar-nofirstevent likelihood.weibull.cp.nof<-function(p){ cumhaz<-p[3]*(end^p[4]-begin^p[4]) cumhaz<-aggregate(cumhaz,by=list(ptno),FUN=sum)[,2] lnhaz<-status*(log(p[3]*p[4]*end^(p[4]-1))) lnhaz<-aggregate(lnhaz,by=list(ptno),FUN=sum)[,2] lik<-r*log(p[2])-n*log(gamma(1/p[2]))+sum(log(gamma(di+1/p[2])))- sum((di+1/p[2])*log(1+p[2]*exp(p[1]*trt)*cumhaz))+ sum(di*p[1]*trt)+sum(lnhaz) -lik} r.weibull.cp.nof<-nlm(likelihood.weibull.cp.nof,c( ,0.5737, ,1.0293),hessian=T,print.level=2)

19 Parametric gamma frailty model Extension: Recurrent events (3)
Gap time model. Information used is Weibull baseline hazard

20 Parametric gamma frailty model Extension: Recurrent events (4)
Gap time model with hazard for first event different and constant Combining gap and calendar time

21 Parametric gamma frailty model Extension: Recurrent events (5)

22 Parametric gamma frailty model Extension: Recurrent events (6)


Download ppt "The parametric frailty model workshop"

Similar presentations


Ads by Google