How do I include measurement errors in a Bernoulli experiment? I would like to understand how to combine a known measurement error in a Bernoulli experiment with the confidence interval in order to calculate error bars. I am performing an experiment that has two outcomes $0$ and $1$ with probabilities $p_0$ and $p_1 = 1-p_0$. If the measurements are perfect, the confidence interval for $N$ measurements is given by
$$
\pm z \sqrt{\frac{p_1(1-p_1)}{N}},
$$
where $z=1.96$ for a $95\%$ confidence interval. In my case however the measurements are imperfect so that with probability $\epsilon_0$ I measure $0$ when the system was really in the state $1$ and with probability $\epsilon_1$ I measure $1$ when the system was really in the state $0$. I assume I can initially prepare $0$ and $1$ perfectly, allowing me to find the errors $\epsilon_0$ and $\epsilon_1$, which I can then use to estimate $p_0$ and $p_1$ in subsequent experiments where the outcome is unknown. My question is therefore how do I combine the known measurement errors with the usual confidence interval?
Any help or references would be greatly appreciated.
 A: We can solve this by maximum likelihood.  Let $X$ be a bernoulli variable with success probability $p_0$. But you observe not $X$, but $Y$ which is $X$ "contaminated", that is, we have 
\begin{align}
    \mathbb{P}(Y=1 | X=0)&= \epsilon_1 \\
    \mathbb{P}(Y=0 | X=0)&= 1-\epsilon_1 \\
    \mathbb{P}(Y=0 | X=1 )&= \epsilon_0 \\ 
    \mathbb{P}(Y=1 | X=1 )&= 1-\epsilon_0
\end{align}
and we asume the "error probabilities " $\epsilon_1, \epsilon_0$ are known.
Now we can find, using conditional probability and the law of total probability, the distribution of $Y$.  Calculate 
$$
   \mathbb{P}(Y=1) = \mathbb{P}(Y=1 | X=0) (1-p_0) + 
                      \mathbb{P}(Y=1 | X=1)p_0 \\  = \epsilon_1 (1-p_0) + (1-\epsilon_0) p_0
$$
and this probability we denote by $p$. Then we observe $n$ independent copies of $Y$, the sum of those is $Z$ which have a binomial distribition with parameters $(n,p)$. We can estimate $p$ as usual by
$$
\hat{p}=Z/n
$$
and then find the maximum likelihood estimator of $p_0$ by solving in
the equation
$$
   \hat{p}=Z/n = \epsilon_1 (1-p_0) + (1-\epsilon_0) p_0
$$
giving 
$$
   \hat{p_0} = \frac{\hat{p}-\epsilon_1}{1-(\epsilon_0+\epsilon_1)}.
$$
Now an example: suppose that $\epsilon_0=\epsilon_1 = 0.05$, $n=100$ and we observe $Z=80$. Then we find 
$$
  \hat{p_0} = \frac{0.8-0.05}{1-0.1}= 0.83...
$$
You want an confidence interval, just use your usual procedure to find an confidence interval for $p$, and then transform the confidence limits in the same way as we transformed the estimate above. (But consider using a better confidence interval than the one you gave).
A: I would start by writing out the likelihood for the data you actually have. The likelihood for $Y=0$ is
$$ \epsilon_0(1-p_0) + (1-\epsilon_0)p_0$$
The likelihood when $Y=1$ is
$$ \epsilon_1 p_0 + (1-\epsilon_1)(1-p_0)$$
The likelihood for the sample is the product of the above terms for the relevant numbers of 0's and 1's. So, if you saw $r$ 1's from a sample of $n$, you get
$$(\epsilon_1 p_0 + (1-\epsilon_1)(1-p_0)^r(\epsilon_0(1-p_0) + 
(1-\epsilon_0)p_0) ^{n-r}$$
Your estimate for $p_0$ is the MLE of this thing and you can get Wald confidence intervals from the second derivative. If you are using R, Ben Bolker's bbmle package can deliver estimates from a supplied likelihood function. I am assuming that the $\epsilon_i$ are known.
It may be possible to get a closed form expression for the variance of the MLE from this equation, but I haven't had my coffee yet this morning and I won't attempt it.
