# Further explanation regarding calculation of E[X^2]

I was reading over the following evaluation of $E[X^2]$ on the following pdf: http://crab.rutgers.edu/~guyk/dmlec/lectures/lec15/l15.pdf.

This part was especially confusing for me: \begin{align} \mathsf E[X^2] & = \sum_{i=1}^n \mathsf E[X_i^2] + 2\sum_{i<j}\mathsf E[X_i\cdot X_j] \\[1ex] & = \sum_{i=1}^n \mathsf E[X_i^2] + 2\sum_{i<j}1\cdot \Pr[X_i=1\cap X_j=1] \\[1ex] & = \sum_{i=1}^n \frac 1 n + 2\left(\frac{n(n+1)}{2}\right)\left(\frac {1}{n(n-1)}\right) \\[1ex] & = n\cdot\frac 1 n + 1 \\[1ex] & = 2 \end{align} This is present on page 3 of the pdf document.

I need help understanding what is going on in lines 1 to 3.

Thanks so much for your help!

• so you have a vector right? when you square it what happens then? Nov 19, 2014 at 21:43

$$X = X_1 + X_2 + \cdots + X_n.$$ Then \begin{align*} X^2 &= (X_1 + X_2 + \cdots + X_n)^2 \\ &= X_1^2 + X_2^2 + \cdots + X_n^2 + 2(X_1 X_2 + X_1 X_3 + \cdots + X_1 X_n) \\ &\quad + 2(X_2 X_3 + X_2 X_4 + \cdots + X_2 X_n) \\ &\quad + \cdots + 2X_{n-1} X_n \\ &= \sum_{i=1}^n X_i^2 + 2 \sum_{i < j} X_i X_j. \end{align*} Then since expectation is a linear operator, the expectation of the sum is equal to the sum of the expectations. As for how $\operatorname{E}[X_i X_j] = 1 \cdot \Pr[(X_i = 1) \cap (X_j = 1)]$, that depends on the distribution that the $X_i$s jointly follow.
• Thanks for your thorough answer! Just some questions: What do the expressions $X_i$, $X_j$, and $i<j$ (below the sigma) represent? Nov 19, 2014 at 22:08
• The meaning should be clear from what was written above. For example: $$\sum_{1 \le i < j \le 4} X_i Y_j = X_1 Y_2 + X_1 Y_3 + X_1 Y_4 + X_2 Y_3 + X_2 Y_4 + X_3 Y_4.$$ It means to take the sum for all pairs $(i,j)$ that satisfy $i < j$. Nov 19, 2014 at 22:25