Dear Martyn, dear all,
I'm looking for a way to model a binomial random variable which suffers from misclassification due to imperfect sensitivity and specificity of our observation/test for positiveness. In other words, some of the observed positive observations may actually be false positives, while other positive observations may have been overlooked entirely.
I've tried the following model, which seems to work:
model {
for (i in 1:N) {
k[i] ~ dbin(sens * p[i] + (1-spec) * (1-p[i]), n[i])
p[i] ~ dbeta(0.5,0.5)
}
sens ~ dunif(0.6,1.0)
spec ~ dunif(0.98,1)
}
However, I'm also interested in modeling all random processes, including the generation of detected true positives and false positives, rather than having these modeled deterministically (as above). Here's where the trouble starts. I assume that the data is the sum of two binomially distributed random variables (true positives and false positives):
model {
for (i in 1:N) {
k[i] ~ dsum(TP[i], FP[i]) # sum of true and false positives
TP[i] ~ dbin(sens, pos[i]) # true positives
FP[i] ~ dbin((1-spec), neg[i]) # false positives
neg[i] <- n[i] - pos[i] # true negatives
pos[i] ~ dbin(p[i], n[i]) # true positives
p[i] ~ dbeta(0.5, 0.5) # unknown prevalence
}
sens ~ dunif(0.6, 1.0) # sensitivity
spec ~ dunif(0.98, 1) # specificity
}Data:
n = c(43, 35)
k = c(16, 26)
N = 2Inital values:
TP = k
FP = (0,0)
pos = k
neg = n-k
p = k/n
sens = 1
spec = 1
I keep getting the error message "Error in node TP[1]; Unobserved node inconsistent with unobserved parents at initialization", even though I have specified the initial values such that the initial model state should fit the data (perfect sensitivity and specificity, sum of unobserved true positives and false negatives equal to observed positives, and expected value for p equal to the observed proportions). I don't quite understand what the problem is here. Any help would be appreciated! Thanks,
Luc
p.s.: I'm using R2jags 0.03-06 in R 2.14.2, and have JAGS 3.1.0 installed on my MacBook Pro OSX 10.7.5
Martyn Plummer
2013-05-30
Martyn Plummer
2013-05-30
Works for me with JAGS 3.3.0 (JAGS 3.3.0 will not let you set initial values for neg, but if I remove that then it works fine).
Anonymous