25
Workshop frailty models Luc Duchateau, Rosemary Nguti and Paul Janssen

Workshop frailty models

Embed Size (px)

DESCRIPTION

Workshop frailty models. Luc Duchateau, Rosemary Nguti and Paul Janssen. Contents. The statistical package R The data set: time to first insemination Inference for shared gamma frailty models Theoretical considerations Fitting parametric and semiparametric models - PowerPoint PPT Presentation

Citation preview

Page 1: Workshop frailty models

Workshop frailty models

Luc Duchateau, Rosemary Nguti and Paul Janssen

Page 2: Workshop frailty models

Contents

• The statistical package R• The data set: time to first insemination• Inference for shared gamma frailty models

– Theoretical considerations– Fitting parametric and semiparametric models

• More flexible shared gamma frailty models– Time-varying covariates– Smoothing splines

• Other approaches for frailty models– Choice of the frailty density– A Bayesian approach for frailty models

Page 3: Workshop frailty models

The statistical package R

• Freeware (unlike Splus)

• Powerful statistical package

• Data handling a bit less powerful

• Downloadable from the Internet– Base– Libraries

• From within R• Download library yourself

Page 4: Workshop frailty models

Installing R via Internet

• Go to www.r-project.org

• Choose option download

• Choose closest mirrorsite http://cran.za.r-project.org/

• Choose operating systemWindows (95 and later)

• Choose subdirectory base

• Choose rw1090.exe

Page 5: Workshop frailty models

Installing additional packages

• Automatically within R– Menu item « Packages»

• « Install Packages from CRAN … »• Choose « survival »

– New session, specify « library(survival) »

• Download zipped package from CRAN– Unzip it under directory

« c:\Program Files\R\rw1091\library »

Page 6: Workshop frailty models

The data set: Time to first insemination

• Database of regional Dairy Herd Improvement Association (DHIA)– Milk recording service– Artificial insemination– Select sample– Subset of 2567 cows from 49 dairy farms

Page 7: Workshop frailty models

Fixed covariates data setinsemfix.dat

Page 8: Workshop frailty models

Time-varying covariates data setinsemtvc.dat

Page 9: Workshop frailty models

Fitting parametric frailty models (1)

• Read the data– insemfix<-read.table("c://insemfix.dat",header=T)

• Create vectors

heifer<- herd stat timeto

insem$heifer110...11

1

1..

49..49

011...11

5332

201...

10338

Page 10: Workshop frailty models

Fitting parametric frailty models (2)

• Derive quantities n, Di and e– n<-length(levels(as.factor(herd)) 49

– Di<-aggregate(stat,by=list(herd),FUN=sum)[,2]

– e<-sum(Di)

1 2 3 … 49

11 23 … 34

Page 11: Workshop frailty models

Fitting parametric frailty models (3)

• Observable likelihood for constant hazard

Page 12: Workshop frailty models

Fitting parametric frailty models (4)

• Calculate observable likelihood for parameters– h=1/p[1], =1/p[2], =p[3]

• Cumulative hazard

• Hazard

Timeto*exp(heifer*p[3])/p[1]cumhaz

aggregate(cumhaz,by=list(herd),FUN=sum)[,2]cumhaz

stat*log(exp(heifer*p[3])/p[1]))lnhaz

aggregate(lnhaz,by=list(herd),FUN=sum)[,2]lnhaz

Page 13: Workshop frailty models

Fitting parametric frailty models (5)

likelihood.exponential<-function(p){cumhaz<-(timeto*exp(heifer*p[3]))/p[1]cumhaz<-aggregate(cumhaz,by=list(herd),FUN=sum)[,2]lnhaz<-stat*log(exp(heifer*p[3])/p[1])lnhaz<-aggregate(lnhaz,by=list(herd),FUN=sum)[,2]lik<-e*log(1/p[2])-n*log(gamma(p[2]))+sum(log(gamma(Di+p[2])))-sum((Di+p[2])*log(1+cumhaz/p[2]))+sum(lnhaz)-lik}

Page 14: Workshop frailty models

Fitting parametric frailty models (6)

0.0317 theta-0.1965,beta ,0146.0 h

days 58))exp(/(2log:heiferson inseminati toeMedian tim betah

initial<-c(100,17,0)t<-nlm(likelihood.exponential,initial,print.level=2)h<-1/t$estimate[1]htheta<-1/t$estimate[2]thetabeta<-t$estimate[3]beta

days 5.47/2log:smultiparouon inseminati toeMedian tim h

Page 15: Workshop frailty models

Interpretation

• From , the heterogeneity parameter, to density for median time to event

calcm<-function(m){(log(2)/(theta*h))^(1/theta) *(1/m)^(1+1/theta)* (1/gamma(1/theta)) *exp(-log(2)/(theta*h*m))}med<-seq(1,100)fmed<-sapply(med,calcm)plot(med,fmed,type="l",xlab="Median time",ylab="Density")

Page 16: Workshop frailty models

Interpretation

Median time

De

nsi

ty

0 20 40 60 80 100

0.0

0.0

10

.02

0.0

30

.04

Page 17: Workshop frailty models

Fitting semiparametric models

library(survival)coxph(Surv(timeto,stat)~heifer+frailty(herd))

Call:coxph(formula = Surv(timeto, stat) ~ heifer + frailty(herd)) coef se(coef) se2 Chisq DF p heifer -0.24 0.0432 0.0430 30.9 1.0 2.7e-08frailty(herd) 205.3 40.9 0.0e+00

Iterations: 10 outer, 23 Newton-Raphson Variance of random effect= 0.123 I-likelihood = -16953

Degrees of freedom for terms= 1.0 40.9 Likelihood ratio test=281 on 41.9 df, p=0 n= 2579

HR=exp(-0.24)=0.79

Page 18: Workshop frailty models

Time-varying covariates data

Contribtion to the denominator:

tij=10 : 2.29tij=55 : 2.61

Page 19: Workshop frailty models

Fitting Cox models withtime-varying covariates (1)

#Read datainsemtvc<-read.table("c://insemtvc.dat",header=T)#Create four column vectors, four different variablesherd<-insemtvc$herdbegin<-insemtvc$beginend<-insemtvc$endstat<-insemtvc$statureum<-insemtvc$ureumheifer<-insemtvc$heiferlibrary(survival)coxph(Surv(begin,end,stat)~heifer+ureum+frailty(herd))

Page 20: Workshop frailty models

Fitting Cox models withtime-varying covariates (2)

Call:coxph(formula = Surv(begin, end, stat) ~ heifer + ureum + frailty(herd)) coef se(coef) se2 Chisq DF p heifer -0.22820 0.0466 0.0464 23.99 1.0 9.7e-07ureum -0.00349 0.0366 0.0358 0.01 1.0 9.2e-01frailty(herd) 177.64 39.4 0.0e+00

Iterations: 10 outer, 23 Newton-Raphson Variance of random effect= 0.116 I-likelihood = -14401.2 Degrees of freedom for terms= 1.0 1.0 39.4 Likelihood ratio test=251 on 41.3 df, p=0 n= 23076

HR=exp(-0.00349)=0.997

Page 21: Workshop frailty models

Fitting Cox models withsmoothing splines (1)

#Read datainsemtvc<-read.table("c://insemtvc.dat",header=T)#Create four column vectors, four different variablesherd<-insemtvc$herdbegin<-insemtvc$beginend<-insemtvc$endstat<-insemtvc$statureum<-insemtvc$ureumheifer<-insemtvc$heiferlibrary(survival)fit<-coxph(Surv(begin,end,stat)~heifer+pspline(ureum,nterm=3,theta=0.5))temp<-order(ureum)plot(ureum[temp],predict(fit,type='terms')[temp,2],type='l',xlab='Ureum',ylab='Risk score')

Page 22: Workshop frailty models

Fitting Cox models withsmoothing splines (2)

Call:coxph(formula = Surv(begin, end, stat) ~ heifer + pspline(ureum, nterm = 3, theta = 0.5))

coef se(coef) se2 Chisq DF p heifer -0.2284 0.0457 0.0457 24.97 1.00 5.8e-07pspline(ureum, nterm = 3, 0.0094 0.0379 0.0349 0.06 1.00 8.0e-01pspline(ureum, nterm = 3, 3.31 1.18 8.7e-02

Iterations: 1 outer, 3 Newton-Raphson Theta= 0.5 Degrees of freedom for terms= 1.0 2.2 Likelihood ratio test=30.2 on 3.18 df, p=1.56e-06 n= 23076

Page 23: Workshop frailty models

Fitting Cox models withsmoothing splines (3)

Ureum

Ris

k sc

ore

1 2 3 4 5 6 7

-0.2

5-0

.20

-0.1

5-0

.10

-0.0

50

.0

Page 24: Workshop frailty models

Fitting the shared normal frailty model (1)

#Read datainsemfix<-read.table("c://docs//onderwijs//frailtymodels//insemfix.dat",header=T)#Create four column vectors, four different variablesherd<-insemfix$herdtimeto<-insemfix$timeto-min(insemfix$timeto)stat<-insemfix$statheifer<-insemfix$heifercoxph(Surv(timeto,stat)~heifer+frailty(herd,distribution="gaussian"))

Page 25: Workshop frailty models

Fitting the shared normal frailty model (2)

Call:coxph(formula = Surv(timeto, stat) ~ heifer + frailty(herd, distribution = "gaussian"))

coef se(coef) se2 Chisq DF p heifer -0.241 0.0431 0.043 31.1 1.0 2.4e-08frailty(herd, distributio 199.9 38.6 0.0e+00

Iterations: 6 outer, 14 Newton-Raphson Variance of random effect= 0.0916 Degrees of freedom for terms= 1.0 38.6 Likelihood ratio test=276 on 39.5 df, p=0 n= 2579