I am trying to derive the following.
The Cramer-von Mises test statistic, defined by $C_n=\int(\widehat{F}_n(t)-F_0(t))^2 \, dF_0(t)$, has the following computational formula:
$$nC_n=\frac{1}{12n}+\sum_{i=1}^n \left(U_{(i)}-\frac{2i-1}{2n}\right)^2, \text{ with } U_{(i)}=F_0(X_{(i)}).$$
I have tried to write it out with all the things I could find online, but every time I get stuck. I started to write, with $u=F_0(t)\Rightarrow t=F_0^{-1}(u)$: \begin{align*} nC_n&=n\int(F_n(t)-F_0(t))^2 \, dF_0(t)=n\int(F_n(F_0^{-1}(u))-u)^2 \, du \\ &=n\int_0^1 \left(\frac 1 n \sum_{i=1}^n\mathbb{1}_{\{F_0(X_i)\leq u\}}-u\right)^2 \,du. \end{align*} And then by splitting the integrals I hoped to get the $\frac{1}{12n}$ and de sum part. But that did not work out. Can somebody help me?
Since $$\sum_{i=1}^n\mathbb{1}_{\{F_0(X_i)\leq u\}}=\sum_{i=1}^n\mathbb{1}_{\{F_0(X_{(i)})\leq u\}}=\sum_{i=1}^n\mathbb{1}_{\{U_{(i)}\leq u\}},$$ one can split integral: $$ nC_n=n\int\limits_0^1\left(\frac{1}{n}\sum_{i=1}^n\mathbb{1}_{\{U_{(i)}\leq u\}}-u\right)^2du = n\sum_{i=0}^n \int\limits_{U_{(i)}}^{U_{(i+1)}} \left(u-\frac{i}{n}\right)^2\, du, $$ where $U_{(0)}=0$, $U_{(n+1)}=1$.
Find integrals and get $$ nC_n = n\sum_{i=0}^n \frac13\left(\left(U_{(i+1)}-\frac{i}{n}\right)^3-\left(U_{(i)}-\frac{i}{n}\right)^3\right)$$ $$= n\sum_{i=1}^n \frac13\left(\left(U_{(i)}-\frac{i-1}{n}\right)^3-\left(U_{(i)}-\frac{i}{n}\right)^3\right) $$ Denote $U_{(i)}-\frac{2i-1}{2n}$ by $z_i$. Then $$U_{(i)}-\frac{i-1}{n}=z_i+\frac1{2n},$$ $$U_{(i)}-\frac{i}{n}=z_i-\frac1{2n}.$$
From $a^3-b^3=(a-b)(a^2+ab+b^2)$ we get $$nC_n= n\sum_{i=1}^n \frac1{3}\left(\left(z_i+\frac1{2n}\right)^3-\left(z_i-\frac1{2n}\right)^3\right) $$ $$ =n\sum_{i=1}^n \frac1{3n}\left(\left(z_i+\frac1{2n}\right)^2+\left(z_i+\frac1{2n}\right)\left(z_i-\frac1{2n}\right)+\left(z_i-\frac1{2n}\right)^2\right) $$ $$ =\sum_{i=1}^n \frac1{3}\left(3z_i^2+\frac1{4n^2}\right)=\frac1{12n}+\sum_{i=1}^n z_i^2. $$