Hi,

i want to use Stan to fit a logistic regression which accounts for imperfect measurement of the outcome. The paper describing the Bayesian approach (McInturff 2004) uses discrete latent parameters in bugs. In order to perform marginalization i turned to an earlier paper describing an EM algorithm to estimate this kind of regression (Magder & Hughes, 1997). This paper gives the conditional probabilities, but my model seems to be not correct as i can’t get reasonable regression estimates even when i impose high sensitivity and specificity.

I think my error could be where I sum up the target density, but frankly i am lost. Anyone who spots my misdoing here?

best wishes, felix

```
data{
int n;
int outcome[n]; //outcome measured with error
int gender[n]; //a predictor
}
parameters {
real<lower=0,upper=1> sensitivity;
real<lower=0,upper=1> specificity;
real slope;
real intercept;
}
transformed parameters {
real linear_predictor[n];
real pie[n];
real likelihood[n];
for (i in 1:n){
linear_predictor[i] = slope*gender[i]+intercept;
pie[i] = exp(linear_predictor[i])/(1+exp(linear_predictor[i])); //probability
//marginalization --> different probabilities for true disease state given observed outcome and linear predictor
if (outcome[i] == 0){
likelihood[i] = log(pie[i]*sensitivity/(pie[i]*sensitivity+pie[i]*(1-specificity)));
} else if (outcome[i] == 1){
likelihood[i] = log(pie[i]*(1-sensitivity)/(pie[i]*(1-sensitivity)+pie[i]*specificity));
}
}
}
model {
sensitivity ~ beta(200,2);
specificity ~ beta(200,2);
intercept ~ normal(0,1);
slope ~ normal(0,1);
target += log_sum_exp(likelihood);
}
```