# Expectation of half of a binomial distribution

If $X$ is a random variable with binomial distribution $B[2n,p]$, with $p=0.5$, then its mean value is $2np = n$. I would like to calculate the mean value of $X$ given that $X$ is at most $n$, i.e.:

$$\frac{1}{Pr[X\leq n]}\cdot \sum_{k=0}^{n} k \binom{2n}{k} p^k q^{2n-k}$$

To calculate the sum, I used the ideas from this question: Expected Value of a Binomial distribution?

and got:

$$\frac{2np}{Pr[X\leq n]}\cdot \sum_{k=1}^{n} \binom{2n-1}{k-1} p^{k-1} q^{(2n-1)-(k-1)}$$

$$= \frac{2np}{Pr[X\leq n]}\cdot \sum_{j=0}^{n-1} \binom{2n-1}{j} p^{j} q^{(2n-1)-j}$$

If the inner sum were for $j=0,…,(2n-1)$, it would be exactly 1 by the binomial theorem. But it is only for half the range, and by symmetry, its value seems to be 0.5. The probability in the denominator is also 0.5, so we get:

$$\frac{2np}{0.5}\cdot 0.5 = 2np = n$$

But this doesn’t make sense, since the expectation of values that are at most $n$, cannot be $n$!

Where is my mistake? And what is the correct expectation?

#### Solutions Collecting From Web of "Expectation of half of a binomial distribution"

Given that $p=q=\frac{1}{2}$,
$$\frac{1}{\mathbb{P}[X\leq n]}\sum_{k=0}^{n}k\binom{2n}{k}\frac{1}{4^n}=\frac{1}{4^n\mathbb{P}[X\leq n]}\sum_{k=0}^{n}k\binom{2n}{k}=\frac{n}{2\mathbb{P}[X\leq n]},$$
but the probability that $X\leq n$ is not $\frac{1}{2}$; it is given by:
$$\mathbb{P}[X=n]+\mathbb{P}[X<n] = \frac{1}{2}+\frac{1}{2\cdot 4^n}\binom{2n}{n},$$
so the wanted expected value is:
$$\frac{n}{1+\frac{1}{4^n}\binom{2n}{n}}.$$

Which by Stirling’s formula is approximately:

$$\frac{n}{1+\frac{1}{\sqrt{\pi n}}} \approx n – \sqrt{\frac{n}{\pi}}$$