4
$\begingroup$

Suppose I have a population of size $n$ in which each element has a probability $p$ of being sick. By sampling this population without replacement, how many elements would I have to sample in average (expected value) to find all the sick ones?

Simulating this in Python, when $n=100$ and $p=0.5$, the expected value is $\approx$99.

$\endgroup$
12
  • 2
    $\begingroup$ is this a home work? $\endgroup$
    – Aksakal
    Commented Aug 3, 2023 at 0:49
  • 2
    $\begingroup$ What @Aksakal is trying to get at is that routine textbook problems, whether homework or not, are treated differently than real statistical problems. It might take less than a minute to read about our policy here ;-). BTW, your CV profile is anonymous and uninformative, so please don't complain that we don't know you. $\endgroup$
    – whuber
    Commented Aug 3, 2023 at 18:23
  • 1
    $\begingroup$ @whuber, I'm well aware of the policy. My public profile shows that I'm a Stack Exchange (SE) user for almost 13 years (with mostly answer-built reputation on other SE sites), also showing links to my GitHub and Twitter accounts. So, even though it's allowed to ask about homework, it can come across as rude when the answer is so easy to find. In any case, the real answer I came here for is still M.I.A. (although Hunaphu below is close), so I would ask that the focus of this interaction would be on the actual answer, as I'm still scratching my head around it. Cheers. $\endgroup$
    – faken
    Commented Aug 3, 2023 at 18:51
  • 1
    $\begingroup$ @whuber, point taken. Regarding your second comment, I've read it and understand it for $p=0.5$, but I can't generalize it to $p\neq 0.5$ and make a connection with Hunaphu's answer below (which contains a formula that perfectly fits the simulation), nor am I understanding how that formula relates to the mentioned hypergeometric distribution. Any hints? $\endgroup$
    – faken
    Commented Aug 4, 2023 at 0:11
  • 2
    $\begingroup$ @faken a simple "no" would suffice. the question is not trivial as isn't its answer, btw. $\endgroup$
    – Aksakal
    Commented Aug 4, 2023 at 21:55

2 Answers 2

2
$\begingroup$

Problem formulation

Index the subjects $1, 2, \ldots, n$ in the order to be observed and for each $k=1,2,\ldots, n$ let $X_k$ be the indicator of whether subject $i$ is sick. The index of the last sick subject, $K,$ is function of the $X_k$ and therefore also is a random variable. (When no subjects are sick, you don't have to sample any at all, in which case we will define $K=0.$) You want to know the expected value of $K.$

Solution

A simple, direct method begins with the distribution function of $K$ defined by

$$F_K(k) = \Pr(K\le k) = \Pr(X_{k+1}=\cdots=X_n= 0) = (1-p)^{n-k}$$

assuming the $\{X_k\}$ are independent. Now

$$E[K] = \int_0^\infty (1 - F_K(k))\,\mathrm dk = \sum_{k=0}^{n-1} (1 - (1-p)^{n-k}) = n - (1-p)\frac{1 - (1-p)^n}{p}.$$

(This is algebraically equivalent to the formulas given in the existing answers, but -- as requested -- is derived in a short, simple manner.)


Because it's easy to make off-by-one errors, let's do some quick checks of simple cases.

  1. $n=0.$ By definition $K=0,$ so the formula had better give $0$ for its expectation. Indeed, $$0 - (1-p)\frac{1 - (1-p)^0}{p} = -(1-p)\frac{0}{p} = 0$$ provided $p\ne 0$ (an exception taken care of below).

  2. $n=1.$ The unique subject is sick with probability $p,$ where $K=1;$ otherwise $K=0.$ Thus the expectation must be $p(1) + (1-p)(0) = p.$ The formula also gives $$1 - (1-p)\frac{1 - (1-p)^1}{p}=p,$$ again provided $p\ne 0.$

  3. $p=1.$ All subjects are sick and so $K=n$ almost surely. The formula also gives $$n - (1-1)\frac{1 - (1-1)^n}{1} = n.$$

  4. $p=0.$ No subjects are sick and so $K=0$ almost surely. The formula is undefined, but we may take the limit as $p\to 0$ from above via L'Hopital's Rule, $$\lim_{p\to 0^+}n - (1-p)\frac{1 - (1-p)^n}{p} = n - \lim_{p\to 0^+} \frac{-1 + (n+1)(1-p)^n}{1} = 0.$$

$\endgroup$
1
$\begingroup$

The number of sick patients on a specific sample follows a hypergeometric distribution. The expectation, once calculated, is $$ N+\frac{(1 - p)^{N + 1} - (1-p)}{p} $$

$\endgroup$
4
  • 1
    $\begingroup$ Thank you for your answer. It would be correct if $p$ was the number of sick patients, but in this case $p$ is the probability of each patient being sick. If we convert the formula to $(N+1)\frac{pN}{pN+1}$, results become very similar to those obtained in simulation, but not quite the same. Therefore, while your answer seems to be on the right path, it's not correct. Another question, I was previously looking into the hypergeometric distribution, but the expected value formula is not quite that one. How did you derive that formula? Thanks. $\endgroup$
    – faken
    Commented Aug 3, 2023 at 11:32
  • $\begingroup$ Yes sorry, I have corrected it. $\endgroup$
    – Hunaphu
    Commented Aug 3, 2023 at 13:43
  • $\begingroup$ This still answers a different question. There's a distinction between sampling a population with, say, 50% sick people, and sampling a population in which each individual has a 50% chance of being sick. $\endgroup$
    – whuber
    Commented Aug 3, 2023 at 14:10
  • $\begingroup$ @Hunaphu, that formula after your second edit, perfectly fits results from the simulation. However, I still don't understand how you derived it from the hypergeometric distribution. More than having a formula, I would like to understand how you got to it. Thanks in advance! $\endgroup$
    – faken
    Commented Aug 3, 2023 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.