# What is the median of Bernoulli distribution?

By definition of median, i.e.

$$P(X\leq m)\geq 1/2 \text{ and } P(X\geq m)\geq 1/2.$$

What is the median of Bernoulli distribution with a probability parameter of $$p=0.2$$ ($$P(X=1)=0.2$$)?

Suppose $$m$$ is the median. Then $$P(X\leq m)\geq 1/2$$ implies $$m\geq0$$. $$P(X\geq m)\geq 1/2$$ implies $$m<0$$. One says m is greater or equal to 0 and the other says it is strictly less than 0. I don't understand where I did wrong.

Here are the CDF plot.

• Your second deduction is incorrect: $P(X\ge m)\ge 1/2$ implies $m\le 1.$
– whuber
Commented Oct 21, 2020 at 15:48
• Is it $m\leq 1$ or $m < 1$? The CDF is right continuous and so is 1-CDF?
– Tan
Commented Oct 21, 2020 at 15:59
• There are only three intervals to consider. For $m\le0,$ $\Pr(X\ge m)=1;$ for $0\lt m\le1,$ $\Pr(X\ge m)=0.8;$ and otherwise for $m\gt 1,$ $\Pr(X\ge m)=0.$ (I took the parameter to be $p=\Pr(X=0).$)
– whuber
Commented Oct 21, 2020 at 15:59
• I updated my question accordingly.
– Tan
Commented Oct 21, 2020 at 16:15
• Your plot of $S$ is incorrect: check its values at $0$ and $1.$
– whuber
Commented Oct 21, 2020 at 16:31

Let $$X \sim \mathsf{Bern}(p=.2)\equiv\mathsf{Binom}(n=1, p=.2).$$ In R, where qbinom is the inverse CDF (quantile function) of a binomial distribution a median $$\eta = 0.$$

qbinom(.5, 1, .2)
[1] 0


$$P(X \le 0) = P(X = 0) = 0.8 \ge 1/2.$$

dbinom(0, 1, .2)
[1] 0.8


And obviously, $$P(X \ge 0) = 1 \ge 1/2.$$

The CDF of $$X$$ is plotted below. The median of $$X$$ is taken to be the value at which the CDF 'curve' is (or 'crosses') $$1/2.$$

curve(pbinom(x, 1, .2), -.5, 1.5, n=10001, xaxs="i", ylab="CDF")
k = 0:1; cdf = pbinom(k, 1, .2)
points(k,cdf,pch=19)
abline(h = .5, col="blue", lwd=2, lty="dotted")


Also, for context, if we simulate $$1000$$ observations from this distribution, we get $$805$$ Failures (0) and $$195$$ Successes. According to R, the sample median is also $$0.$$

set.seed(2020)
x = rbinom(1000, 1, .2)
table(x)
x
0   1
805 195
summary(x)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.000   0.000   0.000   0.195   0.000   1.000

• Re "various versions:" what version would give any different value in this case??
– whuber
Commented Oct 21, 2020 at 16:03
• While making CDF curve, I realized the median is unique in this case. Deleted first line. In this example, there might be various versions of the 80th percentile. Commented Oct 21, 2020 at 16:24
• +1 The plot of the CDF is helpful.
– whuber
Commented Oct 21, 2020 at 16:29
• thank you. But I was asking the theoretical median of the Bernoulli but not based on simulation. Am I missing anything here?
– Tan
Commented Oct 21, 2020 at 16:30
• The simulation is just to show how sample medians may emulate population medians. You need not take it as part of the formal answer to your question. Commented Oct 21, 2020 at 16:32

$$X \sim Bern(0.2)$$

By the definition of median

$$P(X \leq m) \geq 1/2$$ and $$P(X \geq m) \geq 1/2$$

It has

$$m = \begin{cases} 0, \quad p < 1/2\\ [0,1], \quad p = 1/2\\ 1, \quad p > 1/2 \end{cases}$$

It then follows that $$m = 0$$.

• Good. (+1). If $p=1/2,$ the median is ambiguous in $[0,1].$ R chooses $0:$ qbinom(.5,1,.5) returns $0.$. That's because the CDF has $F(0) = 1/2.$ That is: pbinom(0, 1, .5) returns $0.5.$ Commented Oct 21, 2020 at 19:19