Integrating with the indicator function of some random variables I have the following problem.

Suppose $X_1, X_2, \cdots, X_{n} $ are independent random variables which are all distributed in $U [ a, b]$. Define a new random variable $$N_{x, y} = \sum_{k=1}^y I\left\{X_k \le x \right\},\qquad x \in \mathbb{R}$$ so that $N_{x,y}$ is the number of sample variables less than or equal to $x$ with counting only first $y$ samples.

Then how to find the squared $L^2$ norm of $N_{x,y}-x$ over the probability space or integrate the following integral?
$$\left\| N_{x,y}-x \right\|_2^2 = \int \left( N_{x,y} - x \right)^2 dx$$

Can we simplify it by using some ordered random variables?
I assume that your integral is between $a$ and $b$?

Given any values of $X_1$, $X_2$, $X_3$, let us call them $x_1, x_2, x_3$, we can easily integrate some expression involving the indicator functions. Since $X_1$, $X_2$ and $X_3$ are all interchangeable, we can assume that $x_1 &lt; x_2 &lt; x_3$. So the integral is done between these values:

$$ \int_a^b (N_{x,y} - x)^2 dx = \int_a^{x_1} (0 - x)^2 dx + \int_{x_1}^{x_2} (1 - x)^2 dx + \int_{x_2}^{x_3} (2 - x)^2 dx + \int_{x_3}^{b} (3 - x)^2 dx $$

By multiplying out you can see that the term in $x^2$ doesn't change - so you can integrate this over $[a,b]$ and the other terms in the different sub-intervals.

When you have done this, you can take the expectation of this integral over the joint distribution of $X_1, X_2, X_3$. Or are you looking for the variance of this integral (the $L_2$ mean over the probability space?) In either case (since calculating variances involves taking expectations) you are simply going to do a triple integral, in each case over $[a,b]$, and then divide out by $(b-a)^3$.

When you take the expectation, you will be integrating over all cases for the relative size of $x_1, x_2, x_3$, not just the one where $x_1 &lt; x_2 &lt; x_3$. However, these cases are symmetric. If they weren't (eg if $N_{x,y}$ wasn't symmetric in the three random variables, you could just work out the integral above for all 6 different permutations of $1, 2, 3$.
I assume that your integral is between $a$ and $b$?

Given any values of $X_1$, $X_2$, $X_3$, let us call them $x_1, x_2, x_3$, we can easily integrate some expression involving the indicator functions. Since $X_1$, $X_2$ and $X_3$ are all interchangeable, we can assume that $x_1 &lt; x_2 &lt; x_3$. So the integral is done between these values:

$$ \int_a^b (N_{x,y} - x)^2 dx = \int_a^{x_1} (0 - x)^2 dx + \int_{x_1}^{x_2} (1 - x)^2 dx + \int_{x_2}^{x_3} (2 - x)^2 dx + \int_{x_3}^{b} (3 - x)^2 dx $$

By multiplying out you can see that the term in $x^2$ doesn't change - so you can integrate this over $[a,b]$ and the other terms in the different sub-intervals.

When you have done this, you can take the expectation of this integral over the joint distribution of $X_1, X_2, X_3$. Or are you looking for the variance of this integral (the $L_2$ mean over the probability space?) In either case (since calculating variances involves taking expectations) you are simply going to do a triple integral, in each case over $[a,b]$, and then divide out by $(b-a)^3$.

When you take the expectation, you will be integrating over all cases for the relative size of $x_1, x_2, x_3$, not just the one where $x_1 &lt; x_2 &lt; x_3$. However, these cases are symmetric. If they weren't (eg if $N_{x,y}$ wasn't symmetric in the three random variables, you could just work out the integral above for all 6 different permutations of $1, 2, 3$.