Suppose I have a random variable:

\begin{equation} X \sim \begin{cases} 1 \text{ with probability } p \\ y \sim \mathit{unif}(1,k) \text{ with probability } 1 - p \end{cases} \end{equation}

Where $\mathit{unif}$ is the discrete uniform distribution. I am trying to compute the expected value $E[X].$ I think it should just be simply:

\begin{equation} 1 \cdot p + E[y] \cdot (1-p) = 1 \cdot p + (1 + k)/2 \cdot (1-p) \end{equation}

But I am not sure if I am overlooking something.

  • 2
    $\begingroup$ The given answers are both correct for calculating the answer in your concrete problem. I would add, however, that in a general case, you would apply conditional probabilities. For discrete distributions, and naming the random variable that $X$ depends on $Z$, we get: $$\mathbb{P}(X = k)=\sum_{z\in\text{supp}(Z)} \mathbb{P}(X = k | Z = z) \mathbb{P}(Z=z)$$ (law of total probability). This you can then evaluate further (in this concrete example, of course, the sum is only over two values), and in particular evaluate the expectation via $\sum_k k \mathbb{P}(X=k)$. $\endgroup$ Commented Nov 17, 2022 at 15:25
  • $\begingroup$ Hi. I'm used to notation $y \sim \mathit{unif}(\text{some set})$ for the uniform distribution on a given set, but I've never encountered notation $y \sim \mathit{unif}(1,k)$. I don't know what the $1$ and $k$ parameters mean in your case. Could you please explain? From the expected value calculation I can guess that it's maybe the uniform distribution on closed segment $\left[1,k\right]$, or on open segment $\left]1,k\right[$, or on the two-element set $\{1, k\}$, or something else... $\endgroup$
    – Stef
    Commented Nov 18, 2022 at 9:08

2 Answers 2


Your random variable takes the value $1$ with probability $p+\frac{1-p}{k}$, and takes each value $j\in\{2, \dots, k\}$ with probability $\frac{1-p}{k}$. So the expectation is simply $$ \begin{align*} EX = & 1\times \big(p+\frac{1-p}{k}\big) + \sum_{j=2}^k j\times\frac{1-p}{k} \\ = & p+\frac{1-p}{k}\times \sum_{j=1}^k j \\ = & p+\frac{1-p}{k}\times\frac{k(k+1)}{2} \\ = & p+\frac{(1-p)(k+1)}{2}. \end{align*}$$


Your answer is okay and is justified below.

You can write:$$X=B+(1-B)Y$$where $B\sim\text{Bernoulli}(p)$ and $Y\sim\text{Unif}(k)$ are independent random variables.

Then:$$\mathbb EX=\mathbb EB+\mathbb E[(1-B)Y]=\mathbb EB+\mathbb E(1-B)\mathbb EY=p+(1-p)\left(\frac12+\frac12k\right)$$

This way of working is recommendable in situations where the rv is defined by means of cases.


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.