Using probability to estimate a ratio I'm given a bit string of length $n$ and want to approximate the ration of zeros to ones of this string. Given that one chooses $k$ of the $n$ bits, what is the probability that the ratio of zeros to ones of this $k-$bit sample lies in the interval $[\text{actual ratio}-\epsilon, \text{actual ratio}+\epsilon]$? How does this scale when repeating the process several times?
 A: Fix $n$ and $k$. Suppose there are $m$ $0$s in the $n$-bit string (hence $n - m$ $1$s), so that the actual ratio of $0$s to $1$s is $\frac{m}{n - m}$.
Let's calculate $P_j$, the probability of there being exactly $j$ $0$s in your $k$-bit selection (and hence exactly $k - j$ $1$s in your selection). Note that such a selection may not actually be possible. One checks that the probability of selecting exactly $j$ $0$s and then exactly $k - j$ $1$s is:
$$
\frac{m}{n} \cdot \frac{m - 1}{n - 1} \cdots \frac{m - j + 1}{n - j + 1} \cdot \frac{n - m}{n - j} \cdot \frac{n - m - 1}{n - j - 1} \cdots \frac{n - m - (k - j) + 1}{n - k + 1}
$$
Which we can rewrite as
$$
\frac{m!}{(m - j)!} \cdot \frac{(n - j)!}{n!} \cdot \frac{(n - m)!}{(n - m - (k -j))!} \cdot \frac{(n - k)!}{(n - j)!} = \frac{m!(n - m)! (n - k)!}{n! (m - j)!(n - m - (k - j))!}
$$
But any selection with exactly $j$ $0$s will have the same probability. There are $\frac{k!}{j! (k - j)!}$ such selections,which gives
$$
P_j = \frac{k!m!(n - m)! (n - k)!}{j! (k - j)! n! (m - j)!(n - m - (k - j))!}
$$
We can clean this up a bit to get
$$
P_j = \frac{{m\choose j} {n -m \choose k - j}}{{n \choose k}}
$$
which you might have guessed from the start (the number of ways to select $j$ $1$s from the $m$ $1$s multiplied by the number of ways to select $k - j$ $0$s from the $n - m$ $0$s divided by the number of ways to select $k$ bits).

For completeness, we can rewrite $P_j$ in terms of the ratio of $0$s to $1$s in the original string $\rho = \frac{m}{n - m}$ and the ratio of $0$s to $1$s in the sample string $r = \frac{j}{k - j}$. We get
$$
P_r = \frac{{(n\rho)/(\rho + 1) \choose (kr)/(r + 1)} {n/(\rho + 1) \choose k/(r + 1)}}{n \choose k}
$$
This is, if anything, less illuminating. However, it points clearly to the fact that we'll need to make some assumptions about $n, k, \rho$, and $r$ before we can say anything intelligent about the probability of the sample ratio being within some error of the true ratio.
A common assumption is to assume that $n$ is large enough compared to $k$ that we can approximate $P_j$ as a binomial distribution or even a normal distribution with a certain mean and standard deviation, at which point it becomes quite easy to calculate confidence intervals.
