Linearity of maximum function in expectation I was solving an exercise for a probability theory course and stumbled upon the following problem.
Given a continuous random variable $X$, and $\max(a,b) = a$ if $a > b$ and $b$ otherwise, is
$$
E[\max(X, 0)] = \max(E[X], 0)
$$
true in general?
 A: No, it's not. If $E[X] > 0$ then
$$
max(E[X], 0) = E[X]
$$
so you would need
$$
E[X] = E[max(X, 0)]
$$
That can easily be disproved with simple counterexamples.
If $E[X]\le0$ then
$$
max(E[X], 0) = 0
$$
so you would need to have
$$
E[max(X, 0)]=0
$$
That would hold only for constant $X$ equal to $0$.
TL;DR Both ways, it can be easily disproved.
A: Some calculations give, for $X$ a random variable with density $f(x)$ and cdf $ \DeclareMathOperator{\E}{\mathbb{E}} F(x)$
\begin{align}
   \E \max(X,0) &= \int_{-\infty}^\infty \max(x,0) f(x) \; dx \\
                &= \int_{-\infty}^0 0 \cdot f(x)\; dx + \int_0^\infty x \cdot f(x)\; dx \\
                &= \int_0^\infty x \cdot f(x)\; dx
\end{align}
Now, the conditional distribution of $X$ given $X \ge 0$ has density
$\frac{f(x)}{1-F(0)}$ (for $x\ge 0$, zero elsewhere) so find that
\begin{align}
\E \max(X,0) &= \int_0^\infty x \cdot f(x)\; dx \\
             &= \left[ 1-F(0)  \right] \cdot \int_0^\infty x \cdot \frac{f(x)}{1-F(0)}  \; dx \\
  &= \left[ 1-F(0)  \right] \cdot \E\left[ X \mid X \ge 0  \right]
\end{align}
while $\max( \E X, 0)$  will be zero for any random variable with negative expectation.
So any random variable which can take both negative and positive values with positive probability, and which has a negative expectation, gives you an counterexample.
A: It is not true.  A simple counterexample is letting $X \sim N(0, 1)$. Then $\max(E(X), 0) = 0$, whereas
\begin{align}
 & E(\max(X, 0)) = \int_{-\infty}^\infty \max(x, 0)\phi(x)dx = \int_0^\infty x\frac{1}{\sqrt{2\pi}}e^{-x^2/2}dx = \frac{1}{\sqrt{2\pi}} > 0.
\end{align}
In fact, using $\max(a, b) = \frac{1}{2}((a + b) + |a - b|)$, it can be seen that
\begin{align}
& E(\max(X, 0)) = \frac{1}{2}(E(X) + E(|X|)), \\
& \max(E(X), 0) = \frac{1}{2}(E(X) + |E(X)|)). 
\end{align}
Because $|E(X)| \leq E(|X|)$ for any integrable random variable $X$, it always holds that (it's also a consequence of Jensen's inequality $f(E(X)) \leq E(f(X))$ with $f(x) = \max(x, 0)$):
\begin{align}
E(\max(X, 0)) \geq \max(E(X), 0), 
\end{align}
and the strict inequality holds for any random variable such that $E(|X|) > |E(X)|$. Needless to say, there are numerous such random variables.

Assuming $E[|X|] < \infty$, as @Henry commented, a necessary and sufficient condition for $E[|X|] > |E[X]|$ is $P(X > 0) > 0$ and $P(X < 0) > 0$.  To prove it, let $X^+ = \max(X, 0)$ and $X^- = \max(-X, 0)$, then $E[|X|] = E[X^+] + E[X^-]$, $|E[X]| = |E[X^+] - E[X^-]|$.
If $P(X > 0) > 0$ and $P(X < 0) > 0$, then (by, say, Theorem 15.2(ii) of Probability and Measure) $E[X^+] > 0, E[X^-] > 0$, hence $|E[X]| = |E[X^+] - E[X^-]| < E[X^+] + E[X^-] = E[|X|]$.
Conversely, if $|E[X^+] - E[X^-]| < E[X^+] + E[X^-]$, since $|a - b| < a + b$ holds for non-negative $a, b$ if and only if $a \neq 0$ and $b \neq 0$, it follows that $E[X^+] > 0$ and $E[X^-] > 0$, which in turn requires $P(X > 0) > 0$ and $P(X < 0) > 0$.
A: This is false for any random variable $X$ taking both positive and negative values, and true whenever $X$ is either strictly non-negative or strictly non-positive.
It is clear that if $X$ is strictly non-negative, then both the left and right hand side of your equation equal $\mathbb{E}[X] = 0$. Similarly if $X$ is strictly non-positive, then both sides equal zero. Therefore assume otherwise.
In general we have the following:
$$ \mathbb{E}[X] = P(X > 0)\mathbb{E}[X | X > 0] + P(X < 0)\mathbb{E}[X | X < 0] $$
$$ \mathbb{E}[\max(X,0)] = P(X>0)\mathbb{E}[X|X>0].$$
Since $P(X < 0) \not = 0$, we have that $P(X < 0)\mathbb{E}[X|X<0]$ is negative. Thus
$$ \mathbb{E}[\max(X,0)] > \mathbb{E}[X]$$
and also
$$ \mathbb{E}[\max(X,0)] > 0 $$
because $P(X > 0) > 0$ and $\mathbb{E}[X|X>0] > 0$.
Therefore we get the general statement that
$$ \mathbb{E}[\max(X,0)] > \max(\mathbb{E}[X],0)$$
whenever $P(X > 0) \not = 0$ and $P(X < 0) \not = 0$.
