# How do I deal with imperfect detection of a covariate in Bayesian Binomial Regression?

First time question, I've had a search around but couldn't find anything, but apologies if this repeats someone else's question.

I am running a binomial regression with JAGS, attempting to model the probability of pregnancy given the results of a diagnostic test and membership to one of four groups. I also have a random effect for the Site at which these results were collected. Currently, my JAGS code looks like this:

 model   {
for(i in 1:N){
PregStatus[i] ~ dbin(regression_prob[i], 1)
logit(regression_prob[i]) <- intercept[Site[i]] + b1 * x1[i] + GROUP_effect[GROUP[i]]

for(Site_iterator in 1:25){
intercept[Site_iterator] ~ dnorm(mu_int, tau_int)
}


I would like to incorporate the fact that the diagnostic test variable x1 is imperfect (not 100% specificity or sensitivity). I've found many examples in the literature where the dependent variable has imperfect detection, but I am trying to code imperfect detection of the covariate, which then feeds in to a larger regression model.

I've been trying adapt the models found in Valle et al., 2015 (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4634725/), but these are all examples where the response variable has imperfect detection. I thought of adapting the first model in the paper with sensitivity (SN) and specificity (SP) values from the literature like this;

#imperfect detection of x1
tmp[i] <- dnorm(N,1,1)
p1[i]<-tmp[i]/(1+tmp[i])

#modeling disease status d1
d1[i]~dbern(p1[i])

#probability of getting a positive diagnostic test result p2
p2[i]<-ifelse(d1[i]==1,SN,1-SP)

#modeling of diagnostic test result x1
x1[i]~dbern(p2[i])


In the paper tmp[i] is a function of the covariates, so I'm not sure how this should really be produced when it's feeding in to a covariate that is part of a bigger model.

Has anyone got any examples where model covariates have imperfect detection, or any insights on if my model is doing what I hope it does?

• What is the sensitivity/specificity of the pregnancy test? – AdamO Mar 23 '18 at 14:49
• In this example we assume 100%. You could incorporate imperfect detection for this test too, provided you had enough data etc. – HaplessEcologist Apr 16 '18 at 19:17

My answer is intended to suggest a way to think about the problem. You may be able to adapt my formulation to your specific problem and your specific software.

Begin with a model with observed covariates and unobserved parameters: \begin{equation} p(y_{1:n}|x_{1:n},\theta) = \prod_{i=1}^n p(y_i|x_i,\theta) . \end{equation} The posterior distribution for the parameters can be expressed as \begin{equation} p(\theta|y_{1:n},x_{1:n}) \propto p(y_{1:n}|x_{1:n},\theta)\,p(\theta) , \end{equation} where $p(\theta)$ is the prior distribution for $\theta$.

Now generalize the model to allow the covariates to be unobserved. Instead, they are indirectly observed: \begin{equation} p(x_{1:n}|z_{1:n}) = \prod_{i=1}^n p(x_i|z_i) , \end{equation} where $z_{1:n}$ is observed. (The $z_i$ are the test results.) We may think of this of this as a prior for $x_{1:n}$. The posterior distribution for the complete collection of the unobserved entities (parameters and covariates) can be expressed as \begin{equation} p(\theta,x_{1:n}|y_{1:n},z_{1:n}) \propto p(y_{1:n}|x_{1:n},\theta)\,p(\theta)\,p(x_{1:n}|z_{1:n}) . \end{equation} By examining the full conditional posterior distribution for $x_i$, \begin{equation} p(x_i|y_{1:n},z_{1:n},\theta) \propto p(y_i|x_i,\theta)\,p(x_i|z_i) , \end{equation} it can be seen that the observation $y_i$ will help determine the posterior distribution for $x_i$.

Given the specifics in the question (as I understand them), \begin{equation} p(x_i|z_i) = \textsf{Bernoulli}(x_i|\phi_{z_i}) , \end{equation} where $\phi_{z_i}$ is the probability of "success" given the outcome of the test. In particular, \begin{align} p(x_i=1|z_i=1) &= \phi_1 \\ p(x_i=1|z_i=0) &= \phi_0 . \end{align} As I understand it (from reading the wikipedia page regarding the "confusion matrix"), $\phi_1$ can be identified with the Positive Predictive Value (or Precision) and $\phi_0$ can be identified with the False Omission Rate. In order to compute these rates one needs the "prevalence" in addition to specificity and sensitivity.

mef has given a really great answer but with a colleague's help I have managed to adapt the model in the literature example to my specific problem, so I wanted to post the code in case it might help others.

So before I was worrying about tmp, but really it was d1 that I needed to plug in to my logistic regression. The code for imperfect detection of a covariate should look like this;

    model   {
for(i in 1:N){
# These lines describe the response distribution and linear model terms:
PregStatus[i] ~ dbin(regression_prob[i], 1)
logit(regression_prob[i]) <- intercept[Site[i]] + b1 * d1[i] + GROUP_EFFECT[GROUP[i]]

#modeling disease status d1
d1[i]~dbern(pd)

#probability of getting a positive diagnostic test result p2
p2[i]<-ifelse(d1[i]==1,SN,1-SP)

#modeling of diagnostic test result, x1 covariate data goes here
x1[i]~dbern(p2[i])

}

AgeClass_effect <- 0 #Factor level 1
AgeClass_effect ~ dnorm(0, 1)
AgeClass_effect ~ dnorm(0, 1)
AgeClass_effect ~ dnorm(0, 1)

b1 ~ dnorm(0,1) # prior for coefficient of our imperfect test covariate
pd ~ dunif(0,1) # proportion of population that are positive
SN ~ dbeta(0.88,1) #sensitivity of test, I provide an informative prior here using values from the literature
SP ~ dbeta(0.76,1) #specificity, also informative prior

for(Site_iterator in 1:25){
intercept[Site_iterator] ~ dnorm(mu_int, tau_int)
}

mu_int ~ dnorm(0, 0.01)
tau_int <- 1/(s_int * s_int)
s_int ~ dnorm(0, 1)T(0,)

}


So hopefully that framework helps others that might want to model imperfect detection in their covariate, rather than their response variable. Kudos to Valle et al., 2015 for the basis for this code. There are more sophisticated models that estimate SN and SP based on the particulars of the validation of the diagnostic test (sample sizes etc. from the comparison with a 'gold standard' test), which could also be adapted to fit in this model.