I am trying to find the variance but I don't know how to calculate $E(X^2)$, but I do have a process that will enable me to find $E(X)$. How can I find $E(X^2)$?
In my case I have two 6-sided dice, which when thrown sum to D. Then I throw D 15-sided dice and its sum is S. I want to find the variance of S. I can find the expected value by doing (2*3.5)*8 but I don't know how to get the expected value of the square so I can subtract the two to find the variance.
I know it's around 504 but just trying to understand how to calculate it. I also know $E(X)$ here is 56, so $E(X^2)$ is around 560, but how to get the ~560?
The comments have clarified this question significantly. To summarize, we roll 2 6-sided dice and sum the results to get a result $D$, then roll a 15 sided dice $D$ times, summing the results to get $X$. The question is, what is the variance of $X$?
The governing equation is:
$\mathbb{V}[X] = \mathbb{E}_D[\mathbb{V}[X|D]] + \mathbb{V}_D[\mathbb{E}[X|D]]$
Now, $\mathbb{V}[X|D] = D\mathbb{V}[X|D=1]$, as we are just summing up the 15-sided dice. So the first term on the r.h.s. above is $\mathbb{E}[D] \mathbb{V}[X|D=1]$. As $\mathbb{E}[X|D] = D\mathbb{E}[X|D=1]$, once again because we are just summing, the second term on the r.h.s. above is $\mathbb{V}[D]\mathbb{E}[X|D=1]^2$.
The expectation and variance of a discrete uniform variate on $\{1, 2, \dots, N\}$ are $(N+1)/2$ and $(N^2-1)/12$ respectively. Plugging in 6 and 15 in all the appropriate places, and remembering that we are rolling two dice to give us $D$, results in $\mathbb{E}[D] = 7$, $\mathbb{V}[X|D=1] = 224/12$, $\mathbb{V}[D] = 35/6$, and $\mathbb{E}[X|D=1]=8$, for a final result of 504.
Writing a little R script to check:
which looks like a pretty good confirmation that we haven't messed up anywhere.