[Math] Expectation of a floor function applied to a continuous uniform random variable

ceiling-and-floor-functionsprobability

Let $X$ be a random variable, uniformly distributed continuously in the interval $(x_0,x_1), x_0,x_1\in\mathbb{R}$

Obviously, its expectation $E[X]=0.5(x_0 + x_1)$.

Apply round-to-nearest-integer to $X$ (add .5 and floor). What is $E[\lfloor{X}+0.5\rfloor]$ ?

Split the bounds into integral and fractional parts. Let $x_0 = i_0+y_0$ with $i_0 = \lfloor{x_0}\rfloor, y_0=x_0-i_0$ implying $0 \le y_0 \lt 1$, and likewise $x_1= i_1+ y_1$.

There are four cases depending on the fractional parts: (these have been edited from the original to fix the math and improve the presentation)

  • $y_0 < 0.5, y_1 < 0.5$. The interval $(x_0,i_0+0.5)$ rounds to $i_0$ and is of size $0.5 – y_0$. The interval $[i_1-0.5,x_1)$ rounds to $i_1$ and is of size $y_1+0.5$. In between, each unit interval $[i_0+.5+n,i_0+.5+n-1)$ rounds to $i_0+n+1$ for each n, size is 1. Total expectation is $$\frac{(1-i_0-1+i_1-1)(i_0+i_1)/2 + i_0(0.5-y_0) + i_1(0.5+y_1)}{x_1-x_0}$$
  • $y_0 > 0.5, y_1 < 0.5$. $(x_0,i_0+1.5) \leadsto i_0+1$ size $1.5-y_0$ ; $[i_1-0.5,x_1) \leadsto i_1$ size $y_1+0.5$ ; Integers between $[i_0+2\;..\;i_1-1]$ ; Total expectation is $$\frac{(1-i_0-2+i_1-1)(i_0+2+i_1-1)/2+(i_0+1)(1.5-y_0)+i_1(0.5+y_1)}{x_1-x_0}$$
  • $y_0 < 0.5, y_1 > 0.5$. $(x_0,i_0+0.5)\leadsto i_0$ size $0.5 – y_0$ ; $[i_1+0.5,x_1)\leadsto i_1+1$ size $y_1-0.5$ ; Ints between $[i_0+1\;..\;i_1]$ ; Total is $$\frac{(1-i_0-1+i_1)(i_0+1+i_1)/2+i_0(0.5-y_0)+(i_1+1)(y_1-0.5)}{x_1-x_0}$$
  • $y_0 > 0.5, y_1 > 0.5$. $(x_0,i_0+1.5) \leadsto i_0+1$ size $1.5-y_0$ ; $[i_1+0.5,x_1)\leadsto i_1+1$ size $y_1-0.5$ ; Ints between $[i_0+2\;..\;i_1]$ ; Total is $$\frac{(1-i_0-2+i_1)(i_0+2+i_1)/2+(i_0+1)(1.5-y_0)+(i_1+1)(y_1-0.5)}{x_1-x_0}$$

Is my math right? Is my notation right? Is there an easier way to do this?

Best Answer

I don't think that there's an easy way of doing this. Discrete RV's are messy ;0

However, your answer seems wrong. For example, suppose you add some integer (say, $100$) to X. Then the expected value should clearly also increase by $100$. But in your formula, say 1st one, $$(i_0 + i_1)/2 + i_0(0.5-y_0)/(x_1-x_0) + i_1(0.5+y_1)/(x_1-x_0)$$ $E(X)$ would increase by a higher amount due to multiplication by $i_0$ in 2nd term and $i_1$ in 3rd term.

Another way, if $y_0 = y_1 = 0$ then your answer should be $(i_0 + i_1)/2$.