# Moments

**torque**, which equals $rF$. If you have a system of angular forces, you take the sum of all of the $rF$'s. In statistics, it's very similar. The first moment is the mean: $$E(x) = \sum_{i=1}^n p_ix_i $$ Here is the second moment: $$E(x^2) = \sum_{i=1}^n p_ix_i^2 $$ It turns out both of the above are very useful, as this is variance: $$Var(X) = \sum_{i=1}^n p_i(x_i - \mu)^2$$ To think about why that makes sense, imagine the probabilities were uniform, meaning $p(x_i)=\frac{1}{n}$, making the variance equal to $$\frac{1}{n}\sum_{i=1}^n{(x_i - \mu)^2}$$ Now, let's return to the formula above: $$Var(X) = \sum_{i=1}^n p_i(x_i - \mu)^2$$ Note that the mean = $\mu = E(X)$ $$=\sum_{i=1}^n p_i(x_i^2 - 2\mu{}x_i + \mu^2)$$ $$=\sum_{i=1}^n p_ix_i^2 -2\mu\sum_^n p_ix_i + \mu^2\sum_^n p_i$$ $$=E(X^2) - 2\mu E(X) + \mu = E(X^2) - 2E(X)^2 + E(X)^2$$ $$=E(X^2) - E(X)^2$$

# Moment Generating Function

As we can see, we don’t actually have to calculate variance on its own ever. If we calculate the first and second moments, we can figure out the variance. The moment generating function does just this. We can easily find the first and second moment.

Here it is: