Friday, July 15, 2011

Chapter 8 Code for Advanced Bayesian Methods for Medical Test Accuracy



BUGS CODE 8.1

model;
{

th1~dbeta(m1,m0)
ph0~dbeta(s0,r0)
ph1~dbeta(s1,r1)
th0<-1-th1
tpf<- ph1*th1/(ph1*th1+ph0*th0)
fpf<- (1-ph1)*th1/(1-ph1*th1-ph0*th0)
}
# hepatic scintigraphy example
# the following values assume a uniform prior
list(m0= 222,m1=430,s0=28,r0=55,r1=33,s1=322)




BUGS CODE 8.2

model;

{

g00~dgamma(m00,2)
g01~dgamma(m01,2)
g10~dgamma(m10,2)
g11~dgamma(m11,2)

h<-g00+g01+g10+g11

th00<-g00/h
th01<-g01/h
th10<-g10/h
th11<-g11/h

phi00~dbeta(s00,r00)
phi01~dbeta(s01,r01)
phi10~dbeta(s10,r10)
phi11~dbeta(s11,r11)

s1.<-s11+s10
r1.<-r11+r10
s.1<-s01+s11
r.1<- r01+r11

r0.<- r00+r01
s0.<-s00+s01
s.0<-s00+s10
r.0<-r00+r10

# for test 1=1 pd=1
ph1.~dbeta(s1.,r1.)
# for test 1=1 d=0
ph.1~dbeta(s.1,r.1)
# for test 1 = 0 d=1
ph0.~dbeta(s0.,r0.)
# for test 2=1 d=1
ph.0~dbeta(s.0,r.0)

th1.<-th11+th10
th.1<-th01+th11
th0.<-th01+th00
th.0<-th00+th10
# accuracy for test 1
tpf1<-ph1.*th1./pd1
fpf1<-(1-ph1.)*th1./(1-pd1)
pd1<-ph1.*th1.+ph0.*th0.
# accuracy for test 2

tpf2<-ph.1*th.1/pd2
fpf2<-(1-ph.1)*th.1/(1-pd2)
pd2<-ph.1*th.1+ph.0*th.0


}

# metastasis study
list(s00=8,r00=141,s01=65,r01=89,s10=20,r10=29,s11=210,r11=11,
m00=750,m01=257,m10=60,m11=234)
# alzheimers study
list(s00=5,r00=150,s01=85,r01=95,s10=25,r10=25,s11=191,r11=10,
m00=855,m01=280,m10=60,m11=211)


# initial values
list( g00=1, g01=1, g10=1, g11=1)


No comments:

Post a Comment