Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## dsum not working for misclassification model (sum of detected positivites and false positives)

Help
2013-02-27
2013-03-11

• Luc Coffeng
2013-02-27

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) # assuming sensitivity is between 60% and 100%
spec ~ dunif(0.98,1) # assuming specificity is between 98% and 100%
}
```

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 detected and false positives
TP[i] ~ dbin(sens, pos[i]) # detected 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 'true' prevalence
}
sens ~ dunif(0.6, 1.0) # sensitivity
spec ~ dunif(0.98, 1) # specificity
}

Data:
n = c(43, 35)
k = c(16, 26)
N = 2

Inital 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

Last edit: Luc Coffeng 2013-02-28

• Martyn Plummer
2013-03-11

Try upgrading. There was a bug on the likelihood calculations for the binomial distribution with unobserved size parameter that was fixed in 3.2.0. Your model works for me in JAGS 3.3.0.