# Solving for $E(X^2)$ if I know $E(X)$

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?

-
@DilipSarwate This doesn't seem to work for what I am doing. My E(X) system is derived from finding the E(X) of other systems. Do I need to apply the x^2 thing to all the intermediate steps too? –  MyNameIsKhan Jun 16 '12 at 17:17
So you can do this $$E[X^2]=\frac{1}{15}\sum\limits_{i=1}^{15}i^2$$ –  Saurabh Jun 16 '12 at 17:53
This question needs to be closed until the OP edits it. It seems unlikely that the question can be answered in its present form. Too much information is missing, and is coming out in dribs and drabs from the OP in response to the queries in the comments. To the OP: carefully describe the experiment being performed (it seems to be a two-stage experiment) and the random variable whose mean-square value you need to find. Telling us how you proceeded to calculate $E[X]$ would also help. –  Dilip Sarwate Jun 16 '12 at 18:38
As I said, coming out in dribs and drabs, and even if someone goes through all the comments and gleans the important stuff, you have nonetheless provided an incoherent description at best. If you can't be bothered to take the time to edit and re-write your question, I feel no urge to spend my time answering it either. –  Dilip Sarwate Jun 16 '12 at 18:43
To the OP, I have tried to extrapolate the details from these comments. Please let me know if the answer is helpful. If not, please elaborate. I agree with @Dilip that the spirit of this board is that people will help you provided that you are kind and thorough with your thoughts and attempts to solve a problem. It would not hurt you to be more descriptive in your post. –  Justin Jun 16 '12 at 18:51

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:

DiceRoll <- function(n) sample(1:n,1)

x <- rep(0,100000)
for (j in 1:length(x)) {
n <- DiceRoll(6) + DiceRoll(6)
for (i in 1:n) x[j] <- x[j] + DiceRoll(15)
}

var(x)
[1] 504.4255

which looks like a pretty good confirmation that we haven't messed up anywhere.

-
I appreciate this answer but I do not understand it at all, to be honest. I don't know all those math symbols/jargon all that well and am only really familiar with algebra. –  MyNameIsKhan Jun 16 '12 at 18:53
$\mathbb{V}[X]$ is the variance of $X$, $\mathbb{E}[X|D]$ is the expected value of $X$ given the value of $D$, $\mathbb{E}_D[\mathbb{V}[X|D]]$ is the expected value of [the variance of $X$ given $D$], and so forth. For the latter term, to clarify a little more, we calculate the variance of $X$ given that we are rolling $D$ 15-sided dice, then we take the expected value of that, as we don't actually know how many 15-sided dice we are going to roll. Hopefully you can figure out the rest from that - especially with the numbers to help. –  jbowman Jun 16 '12 at 19:30
I was able to recreate your result, but does the equation change if there are more systems? Say I throw a die and its sum = A, I throw A dice, their sum=B, I throw B dice, and so on. Does the equation just apply to the last step if I know the expected value up until the last step? –  MyNameIsKhan Jun 16 '12 at 21:27
No, unfortunately it doesn't. The difficulty is that it isn't sufficient to know the mean and variance of, e.g., the second step in order to calculate the last step, you actually have to know all the probabilities. Sometimes you're just better off simulating, as with the code fragment above, rather than fighting your way through a lot of algebra which you will then just have to program anyway (or perhaps set up in a spreadsheet) because there are too many possible cases to deal with by hand. –  jbowman Jun 16 '12 at 23:22
But can i use variance and ev of old systems to find those variables for the new system recursively? –  MyNameIsKhan Jun 16 '12 at 23:48


$$\var(S) = \var(\E(S\mid D)) + \E(\var(S\mid D)).$$ I.e. the total variance of $S$ is the variance of the conditional expected value plus the expected value of the conditional variance. Below I'll say something about what that means.

You throw two 6-sided dice and get a number $D$ in the set $\{2,3,4,\ldots,12\}$, with respective probabilities $1/36, 2/36, 3/36, 4/36, 5/36, 6/36, 7/36, 6/36, 5/36,4/36,3/36,2/36,1/36$. We have $\E(D)=7$ and $\var(D)=35/6$.

Now suppose you throw a 15-sided die. You get a mean of $8$ and a variance of $56/3$ (if my hasty arithmetic is right).

If you throw $d$ 15-sided dice and sum the outcomes, you have a mean of $8d$ and a variance of $56d/3$.

So the conditional expected value of the sum $S$ given the event that $D=d$ is $8d$ and the conditional variance of the sum $S$ given the event that $D=d$ is $56d/3$. I.e. $$\E(S\mid D=d) = 8d,\qquad \var(S\mid D=d)=\frac{56d}{3}.$$

Next we have $\E(S\mid D)$ and $\var(S\mid D)$ as random variables in their own right, since they depend on the random variable $D$, and we get: $$\E(S\mid D) = 8D, \qquad \var(S\mid D)= \frac{56D}{3}.$$

So $$\E(\var(S\mid D)) = \E\left(\frac{56D}{3}\right) = \frac{56}{3} \E(D) = \frac{56}{3}\cdot 7 = \frac{392}{3},$$ and $$\var(E(S\mid D)) = \var(8D) = 8^2\var(D) = 64\cdot \frac{35}{6} = \frac{1120}{3}.$$

Now add: $$\frac{392}{3} + \frac{1120}{3} = \frac{1512}{3} = 504.$$

Later note: $\var(\E(S\mid D))$ is the part of the variance of $S$ that is "explained" by the variability of $D$. The other term, $\E(\var(S\mid D))$ is the part of the variance of $S$ that comes from the randomness that remains in $S$ after $D$ is determined, so it's the "unexplained" component of the variance of $S$.

-
What if i have multiple systems? I got the 504 but what if it's deeper? –  MyNameIsKhan Jun 16 '12 at 22:22

Another problem to point out with the premise of the question is that for an arbitrary random variable $X$ there is literally no relationship whatsoever between $E(X)$ and $E(X^2)$. The easiest way to see this might be to take a variable $X$ that has probability $\frac{1}{2n+1}$ of being each of the numbers $-n, -n+1, \ldots, 0, \ldots, n-1, n$. Then the expected value of $X$ itself, is obviously zero, but $E(X^2) = \frac{1}{2n+1}\sum_{i=-n}^ni^2 = n(n+1)/3$; the value of $E(X)$ (which is always 0) tells us nothing at all about the value of $E(X^2)$ (which varies with $n$ and can be arbitrarily large). It's impossible to compute $E(X^2)$ from $E(X)$, so you have to go through at least some semblance of the computation that other answers here have outlined.

-

Well, the good news is that if you can find $E(X)$ you should be able to find $E(X^2)$.

Given that you have a 2-stage discrete process, perhaps it would help you to visually "chart" out the possibilities for S. You should be able to then see how to calculate

$E(X)=\sum_i x_ip(x_i)$

If I understand the problem correctly, you have to roll N 6-sided dice and then roll $M=\sum_in_i$ 15-sided dice in order to find the moments of the second process.

Steps/hints

-Create your discrete pmf for the first RV

-Use this to create a discrete pmf of the second RV

-Use this pmf to calculate $E(X),E(X^2).$

The "trick" here is to recall (or observe) that the $E(Y)$ can be thought of as a collection of $E(Y|X=x)$-type outcomes that should be relatively easy to compute. While in this case a 15-sided die is slightly more difficult to deal with, it doesn't change the methodology from the below example.

Simplified example

Suppose you flip a coin and then roll 1 die if it comes up heads and 2 dice if it comes up tails. What is $E$(dice roll)?

It should be easy to see that the first process has a simple pmf that is $\frac12$ for heads and tails. Under the event $(Y|X=0)$, for $0$="heads", $E(Y)=\frac16(1+2+\cdots+6)=3.5$ while the event $(Y|X=1)$ yields $E(Y)=\sum_{i=2}^{12}x_ip(x_i)=7.$

Think about what $E(Y)$ is in this simplified case, and think about how this would impact a complete pmf for Y.

Then extrapolate.

-
Similar to what I said on the other answer, I do not understand this much. I have no idea what a discrete pmf is or how it applies here. The 504 number is the correct answer but I am trying to understand how to find it. –  MyNameIsKhan Jun 16 '12 at 19:02
hmm, ok. Well I am somewhat curious as to how you were given this problem without knowing anything about probability mass functions. I would start here: en.wikipedia.org/wiki/Probability_mass_function –  Justin Jun 16 '12 at 19:07
I understand basic probability and the basic concepts of variance and standard deviation, just not all the jargon and gritty-level mathematical stuff –  MyNameIsKhan Jun 16 '12 at 19:09
also, do you understand what P(Y|X) means? It is the probability of "Y" given that X happened. So, an event like P(Y|X=1) in my above example would be "the probability of Y (the dice roll) given that X=1 (a tails was flipped on the coin). If I add up all of the individual (Y|X=x) I can get the information I need about Y. In your example, imagine trying to figure out the possible outcomes for the 15-sided dice roll, AFTER you know the result of the first dice roll. –  Justin Jun 16 '12 at 19:10
Yes I know of that (Bayes Rule). I explained earlier how I calculated E(X). Can I just directly modify that to get E(X^2)? –  MyNameIsKhan Jun 16 '12 at 19:12