Suppose that Y1,…,Yn+1 is a random sample from a continuous distribution function F. LetX∼Uniform{1,…,n} be independent of the Yi‘s. How can I compute E[∑Xi=1I{Yi≤Yn+1}]?

**Answer**

Here is an alternative answer to @Lucas’ using the law of iterated expectations:

E[X∑i=11(Yi≤Yn+1)]=E[E[X∑i=11(Yi≤Yn+1)|X]]=E[X∑i=1E[1(Yi≤Yn+1)|X]]=E[X∑i=1E[1(Yi≤Yn+1)]]=E[X∑i=1E[E[1(Yi≤Yn+1)|Yn+1]]]=E[X∑i=1E[F(Yn+1)]]=E[X]E[F(Yn+1)]=n+12E[F(Yn+1)]

The third step follows from independence of Yi and Yn+1 from X; the fourth step is again an application of the law of iterated expectations; the last step is simply an application of the formula for the expectation of a discrete uniform random variable.

By inverting the order of integration, we derive the remaining expectation:

E[F(Yn+1)]=∫∞−∞F(y)dF(y)=∫∞−∞∫y−∞dF(x)dF(y)=∫∞−∞∫∞xdF(y)dF(x)=∫∞−∞(1−F(x))dF(x)=1−E[F(Yn+1)]

which implies E[F(Yn+1)]=12. Hence:

E[X∑i=11(Yi≤Yn+1)]=n+14

**Attribution***Source : Link , Question Author : hadi , Answer Author : Daneel Olivaw*