Wednesday, July 10, 2013



Chapter 5



BUGS CODE 5.1 
 
model;

{

# posterior distribution of mortality probabilities

for( i in 1:a){ q[i]~dbeta(m[i], b[i])}

for( i in 1:a){b[i]<- O[i]-m[i]}

# survival probabilities

for( i in 1:a){p[i]<-1-q[i]}

# overall survival

s <- p[1]*p[2]*p[3]*p[4]*p[5]*p[6]*p[7]*p[8]*p[9]*p[10]

}

# data from table 5.2

# the O vector is the number available at the beginning of the period
 
list(a=10, m=c(6,5,5,5,5,4,5,5,5,5),

O=c(1000,994,989,984,979, 974,970,965,960,955,950))

# initial values

list(q=c(.5,.5,.5,.5,.5,.5,.5,.5,.5,.5))

BUGS CODE 5.2 
 
Model;

{

# posterior distribution of mortality probabilities

for( i in 1:a){ q[i]~dbeta(m[i], b[i])}

for( i in 1:a){b[i]<-Op[i]-m[i]}

# the below statement applies to Table 5.4

for( i in 1:a){Op[i]<-O[i]-w[i]}

# below is applied when only half the withdrawals are used

# Applies to Table 5.6

#for( i in 1:a){Op[i]<-O[i]-w[i]/2}

# cause specific net data

#for( i in 1:a){Op[i]<-O[i]-w[i]/2-do[i]}

# survival probabilities

for( i in 1:a){p[i]<-1-q[i]}

# overall survival

#s <- p[1]*p[2]*p[3]*p[4]*p[5]*p[6]

# Overall probability of response problem 4

P<- p[1]*p[2]*p[3]*p[4]*p[5]

}
 
# data from table 5.4

# the O vector is the number available at the beginning of the period

# w vector is the number of withdrawals

# m vector is the number of deaths

list(a=6, m=c(207,41,9,7,18,10),

O=c(450,235,184,166,148,118),

w=c(8,10,9,11,12,9))

# data for crude cause specific information

list(a=6, m=c(51,9,5,6,11,5),

O=c(450,235,184,166,148,118),

w=c(8,10,9,11,12,9))

# data for net cause specific information

list(a=6, m=c(51,9,5,6,11,5),

O=c(450,235,184,166,148,118),

w=c(8,10,9,11,12,9),

do=c(156,32,4,1,7,5))

# data for clinical trial problem 4

list(a=5, m=c(1,1,3,4,5),

O=c(34,30,27,20,12),

w=c(3,2,4,5,1))

# initial values

list(q=c(.5,.5,.5,.5,.5,.5))

# initial values for problem 4

list(q=c(.5,.5,.5,.5,.5))


BUGS CODE 5.3

model;

{

#Dirichlet Distribution of those that do not withdraw in interval

# i is the year number

for ( i in 1:21) {for (j in 1:5){x[i,j]~dgamma(m[i,j],2)}}

for( i in 1:21){ s[i]<-sum(x[i,])}

for ( i in 1:21) {for ( j in 1:5){q[i,j]<-x[i,j]/s[i]}}

# q[i,j] have a dirichlet distribution

#q[1,1] is the probability of survival for year 1 interval (0,1)

# q[i,j] the probability of category j of year i

# Dirichlet Distribution of those that do withdraw in interval

# i is the year number

for ( i in 1:21) {for (j in 1:5){y[i,j]~dgamma(n[i,j],2)}}

for( i in 1:21){ sw[i]<-sum(y[i,])}

for ( i in 1:21) {for ( j in 1:5){qw[i,j]<-y[i,j]/sw[i]}}

# qw[i,j] have a dirichlet distribution

#qw[1,1] is the probability of survival for year 1 interval (0,1)

# qw[i,j] the probability of category j of year i
 



}
 
list(n=structure(.Data=c(

746,60,2,6,153,

727,45,5,12,134,

611,32,1,9,146,

597,27,4,12,145,

505,18,1,10,129,

462,18,2,7,122,

439, 21,2,6,131,

393,9,1,4,95,

322,8,1,7,74,

314,4,1,8,73,

257,16,1,4,78,

229,5,1,6,63,

158, 1,1,2,51,

146,2,1,3,30,

119,4,1,2,44,

112,3,1,4,24,

83,2,1,2,24,

70,1,1,4,11,

44,2,1,4,16,

46,1,2,2,16,

41,1,1,2,9),.Dim=c(21,5)),

 

 

m=structure(.Data=c(

17203,2382,57,650,571,

14053,1690,36,351,113,

11564,1162,29,283,101,

9522,864,30,258,100,

7882,534,34,188,108,

6487,433,34,185,89,

5393,271,18,132,71,

4386,196,25,129,67,

3528,178,14,101,72,

2866,107,18,86,49,

2294,85,11,51,34,

1799,45,12,60,31,

1377, 48,6,47,26,

1072,26,13,40,22,

818,22,3,37,19,

600,14,2,26,15,

420,17,1,14,13,

285,10,2,10,10,

193,2,1,7,4,

118, 1,4,7,5,

50,3,2,3,1),.Dim=c(21,5)))
 


# activate initial values from specification tool


BUGS CODE 5.4
 
 
Model;



{

# Study 1

# posterior distribution of mortality probabilities

for( i in 1:a){ q1[i]~dbeta(m1[i], b1[i])}

for( i in 1:a){b1[i]<-Op1[i]-m1[i]}

for( i in 1:a){Op1[i]<-O1[i]-w1[i]}

# below is applied when only half the withdrawals are used

# for( i in 1:a){Op1[i]<-O1[i]-w1[i]/2}

# survival probabilities

for( i in 1:a){p1[i]<-1-q1[i]}

# overall survival

s1 <- p1[1]*p1[2]*p1[3]*p1[4]*p1[5]*p1[6]

# Study 2

# posterior distribution of mortality probabilities

for( i in 1:a){ q2[i]~dbeta(m2[i], b2[i])}

for( i in 1:a){b2[i]<-Op2[i]-m2[i]}

for( i in 1:a){Op2[i]<-O2[i]-w2[i]}

# below is applied when only half the withdrawals are used

# for( i in 1:a){Op2[i]<-O2[i]-w2[i]/2}

# survival probabilities

for( i in 1:a){p2[i]<-1-q2[i]}

# overall survival

s2 <- p2[1]*p2[2]*p2[3]*p2[4]*p2[5]*p2[6]

d<-s1-s2

}
 
# data from table 5.4

# the O vector is the number available at the beginning of the period

# w vector is the number of withdrawals

# m vector is the number of deaths

list(a=6, m1=c(207,41,9,7,18,10),

O1=c(450,235,184,166,148,118),

w1=c(8,10,9,11,12,9),

m2=c(200,39,10,16,24,15),

O2=c(410,202,154,137,114,87),

w2=c(8,9,7,7,3,6))

# data for crude cause specific information Table 5.8

list(a=6, m=c(51,9,5,6,11,5),

O=c(450,235,184,166,148,118),

w=c(8,10,9,11,12,9))

# data for net cause specific information Table 5.8

list(a=6, m=c(51,9,5,6,11,5),

O=c(450,235,184,166,148,118),

w=c(8,10,9,11,12,9),

do=c(156,32,4,1,7,5))

# initial values

list(q=c(.5,.5,.5,.5,.5,.5))

BUGS CODE 5.5 
 
model;

{

# probabilities of death first study

q1[1]~dbeta(207,243)

q1[2]~dbeta(41,194)

q1[3]~dbeta(9,175)

q1[4]~dbeta(7,159)

q1[5]~dbeta(18,130)

q1[6]~dbeta(10,108)

# probabilites of death second study

q2[1]~dbeta(200,200)

q2[2]~dbeta(39,163)

q2[3]~dbeta(10,149)

q2[4]~dbeta(16,121)

q2[5]~dbeta(24,99)

q2[6]~dbeta(15,72)

# survival probabilities first study

p1[1]~dbeta(243,207)

p1[2]~dbeta(194,41)

p1[3]~dbeta(175,9)

p1[4]~dbeta(159,7)

p1[5]~dbeta(130,18)

p1[6]~dbeta(108,10)

# survival probabilities second study

p2[1]~dbeta(200,200)

p2[2]~dbeta(163,39)

p2[3]~dbeta(149,10)

p2[4]~dbeta(121,16)

p2[5]~dbeta(99,24)

p2[6]~dbeta(72,15)

# posterior distribution of the number of deaths and survivals

for ( i in 1:6){m1[i]<-q1[i]*T1[i]}

for ( i in 1:6){m2[i]<-q2[i]*T2[i]}

for ( i in 1:6){s1[i]<-p1[i]*T1[i]}

for ( i in 1:6){s2[i]<-p2[i]*T2[i]}

# numerator of odds ratio

ORN<- m1[1]*s2[1]/850+m1[2]*s2[2]/437+m1[3]*s2[3]/343+m1[4]*s2[4]/303+m1[5]*s2[5]/271+m1[6]*s2[6]/205

# denominator of odds ratio

ORD<- m2[1]*s1[1]/850+m2[2]*s1[2]/437+m2[3]*s1[3]/343+m2[4]*s1[4]/303+m2[5]*s1[5]/271+m2[6]*s1[6]/205

# odds ratio

OR<-ORN/ORD

}

# see Table 5.16
 
list(T1=c(450,235,184,166,148,118),

T2=c(400,202,159,137,123,87))

# initial values

list(p1=c(.5,.5,.5,.5,.5,.5),p2=c(.5,.5,.5,.5,.5,.5),

q1=c(.5,.5,.5,.5,.5,.5),q2=c(.5,.5,.5,.5,.5,.5))









BUGS CODE 5.6
 
 



 

model;

{

# binomial distribution of the number of deaths

for ( i in 1:a){d[i]~dbin(q[i],O[i])}

# prior distribution for probability of death

for ( i in 1:a){ q[i]~dbeta(.01,.01)}

# survial probabilities for each event

for ( i in 1:a){ p[i]<-1-q[i]}

# product limit survival probabilities

s[1]<-p[1]

for ( i in 2:a){s[i]<-s[i-1]*p[i]}

for( i in 1:a){ m[i]<-q[i]*O[i]}

# avg numberof deaths

mm<-mean(m[])

# total number of deaths

tm<-a*mm

# average survival time

mt<-mean(t[])

# total survival time for a patients

tt<-a*mt

# average hazard

ah<-tm/tt


 
}
 
# data from table 5.18

list(a=26, O=c(26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1), d=c(1,1,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,0,1,1,0,1,1,1,1),

t=c(2,5,8,9,14,17,26,28,35,39,41,45,49,58,62,63,74,78,82,88,

91,94,95,99,100,104))

# data from table 5.20

list( a=23,

O=c(23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1),

d=c(1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,1),

t=c(2,5,7,11,12,25,31,32,37,40,51,61,63,68,75,78,92,

97,99,105,110,110,133))

# initial values table 5.18

list(q=c(.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5))

# inital values table 5.20

list(q=c(.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,

.5,.5,.5,.5,.5,.5))
 
 
 


 
 
 

 
 

No comments:

Post a Comment