# NOT RUN {
## ===================================================== ##
## 2-TEST EXAMPLE: Strongyloides ##
## ----------------------------------------------------- ##
## Two tests were performed on 162 humans ##
## -> T1 = stool examination ##
## -> T2 = serology test ##
## Expert opinion generated the following priors: ##
## -> SE1 ~ dbeta( 4.44, 13.31) ##
## -> SP1 ~ dbeta(71.25, 3.75) ##
## -> SE2 ~ dbeta(21.96, 5.49) ##
## -> SP2 ~ dbeta( 4.10, 1.76) ##
## The following results were obtained: ##
## -> 38 samples T1+,T2+ ##
## -> 2 samples T1+,T2- ##
## -> 87 samples T1-,T2+ ##
## -> 35 samples T1-,T2- ##
## ===================================================== ##
## how is the 2-test model defined?
define_x(2)
define_prior2(2)
## fit Strongyloides 2-test model
## a first model assumes conditional independence
## -> set covariance terms to zero
strongy_indep <-
truePrevMulti2(
x = c(38, 2, 87, 35),
n = 162,
prior = {
TP ~ dbeta(1, 1)
SE[1] ~ dbeta( 4.44, 13.31)
SP[1] ~ dbeta(71.25, 3.75)
SE[2] ~ dbeta(21.96, 5.49)
SP[2] ~ dbeta( 4.10, 1.76)
a[1] <- 0
b[1] <- 0
})
## show model results
strongy_indep
## fit same model using 'list-style'
strongy_indep <-
truePrevMulti2(
x = c(38, 2, 87, 35),
n = 162,
prior =
list(
TP = list(dist = "beta", alpha = 1, beta = 1),
SE1 = list(dist = "beta", alpha = 4.44, beta = 13.31),
SP1 = list(dist = "beta", alpha = 71.25, beta = 3.75),
SE2 = list(dist = "beta", alpha = 21.96, beta = 5.49),
SP2 = list(dist = "beta", alpha = 4.10, beta = 1.76),
a1 = 0,
b1 = 0
)
)
## show model results
strongy_indep
## fit Strongyloides 2-test model
## a second model allows for conditional dependence
## -> a[1] is the covariance between T1 and T2, given D+
## -> b[1] is the covariance between T1 and T2, given D-
## -> a[1] and b[1] can range between +/- 2^-h, ie, (-.25, .25)
strongy <-
truePrevMulti2(
x = c(38, 2, 87, 35),
n = 162,
prior = {
TP ~ dbeta(1, 1)
SE[1] ~ dbeta( 4.44, 13.31)
SP[1] ~ dbeta(71.25, 3.75)
SE[2] ~ dbeta(21.96, 5.49)
SP[2] ~ dbeta( 4.10, 1.76)
a[1] ~ dunif(-0.25, 0.25)
b[1] ~ dunif(-0.25, 0.25)
})
## explore model structure
str(strongy) # overall structure
str(strongy@par) # structure of slot 'par'
str(strongy@mcmc) # structure of slot 'mcmc'
strongy@model # fitted model
strongy@diagnostics # DIC, BGR and Bayes-P values
## standard methods
print(strongy)
summary(strongy)
par(mfrow = c(2, 2))
plot(strongy) # shows plots of TP by default
plot(strongy, "SE[1]") # same plots for SE1
plot(strongy, "SE[2]") # same plots for SE2
plot(strongy, "SP[1]") # same plots for SP1
plot(strongy, "SP[2]") # same plots for SP2
plot(strongy, "a[1]") # same plots for a[1]
plot(strongy, "b[1]") # same plots for b[1]
## coda plots of all parameters
par(mfrow = c(2, 4)); densplot(strongy, col = "red")
par(mfrow = c(2, 4)); traceplot(strongy)
par(mfrow = c(2, 4)); gelman.plot(strongy)
par(mfrow = c(2, 4)); autocorr.plot(strongy)
# }
Run the code above in your browser using DataLab