model {
# Define likelihood model for data:
# Carbapenem resistance in hospital (gp, volunteer, and outpatient) samples
# is Bernoulli distributed with probability wc.prob (gp.prob, v.prob,
# and o.prob)
for (p in 1:N_patients)
{
h_resist[p] ~ dbern(cstwtw.prob[ward[h_sample_GUID[p]],
clinical[sample_type[h_sample_GUID[p]]],
sample_type[h_sample_GUID[p]]])
}
for (gp in 1:N_gp)
{
gp_resist[gp] ~ dbern(gpcst.prob[gp_clinical,
sample_type[gp_sample_GUID[gp]]])
}
for (v in 1:N_volunteers)
{
v_resist[v] ~ dbern(vcst.prob[v_clinical,
sample_type[v_sample_GUID[v]]])
}
for (o in 1:N_outpatients)
{
o_resist[o] ~ dbern(ocst.prob[o_clinical,
sample_type[o_sample_GUID[o]]])
}
# ------------------------
# Define the priors:
# Prior distribution for wt.effect (log-odds for each ward type). Sample
# different wt.effect from normal distribution for each ward type and
# convert to a probability). Put intercept here.
for (wt in hosp_wardtypes)
{
wt.effect[wt] ~ dnorm(intercept, tau.wt)
logit(wt.prob[wt]) <- wt.effect[wt]
}
# equivalent to wt.effect
nh.effect ~ dnorm(intercept, tau.wt)
logit(nh.prob) <- nh.effect
# ------------------------
# Prior distribution for w.effect (log-odds for each ward). Sample
# different ward.effect from normal distribution for each clinical class and
# convert to a probability). w.effect depends on wardtype effect.
for (w in hosp_wards)
{
w.effect[w] ~ dnorm(wt.effect[ward_type[w]], tau.w)
}
# equivalent to wtw.effect
gp.effect ~ dnorm(nh.effect, tau.w)
logit(gp.prob) <- gp.effect
v.effect ~ dnorm(nh.effect, tau.w)
logit(v.prob) <- v.effect
o.effect ~ dnorm(nh.effect, tau.w)
logit(o.prob) <- o.effect
# ------------------------
# Prior distribution for wc.effect (log-odds for each clinical class). Sample
# different clin.effect from normal distribution for each clinical class and
# convert to a probability). Since intercept is in wt, set mean to 0.
clin.effect[ncarr] ~ dnorm(0, 0.001) # params = 1
clin.effect[nclin] <- -clin.effect[ncarr]
# Prior distribution for st.effect (log-odds for each sample type). Sample
# different st.effect from normal distribution for each sample type and
# convert to a probability). cst.effect depends on clin.effect and is
# different for each sampletype. cst.effect (clinical state) and w.effect are
# independent. cstwtw.effect is different for each ward, clinical state, and
# sampletype.
for (c in c(ncarr, nclin))
{
for (st in sampletypes)
{
cst.effect[c,st] ~ dnorm(clin.effect[c], tau.cst)
logit(cst.prob[c,st]) <- cst.effect[c,st]
for (w in hosp_wards)
{
cstwtw.effect[w,c,st] <- cst.effect[c,st] + w.effect[w]
logit(cstwtw.prob[w,c,st]) <- cstwtw.effect[w,c,st]
}
# equivalent to cstwtw.prob
logit(gpcst.prob[c,st]) <- cst.effect[c,st] + gp.effect
logit(vcst.prob[c,st]) <- cst.effect[c,st] + v.effect
logit(ocst.prob[c,st]) <- cst.effect[c,st] + o.effect
}
}
# ------------------------
# Prior value for intercept
intercept ~ dnorm(0, 0.001)
# Prior values for precision
tau.wt ~ dgamma(0.001, 0.001)
tau.w ~ dgamma(0.001, 0.001)
tau.cst ~ dgamma(0.001, 0.001)
# Convert precisions to sd
sd.wt <- 1/sqrt(tau.wt)
sd.w <- 1/sqrt(tau.w)
sd.cst <- 1/sqrt(tau.cst)
#monitor# full.pd, dic, deviance, intercept, gp.prob, v.prob, o.prob, sd.wt, sd.w, sd.cst
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.