# Expectation of random variables

Suppose, $X_1,X_2,X_3,X_4$ are i.i.d. random variables with values 1 and -1 with prob 0.5 each. Then find the value of $E(X_1+X_2+X_3+X_4)^4$.

Ans:

Let, $Y=\sum_{1}^{4}X_{i}$ Now, Y takes values 4,-4,2,-2,0 with the following probabilities:

$P(Y=0)=\frac{6}{2^4}$

$P(Y=2)=\frac{4}{2^4}=P(Y=-2)$

$P(Y=4)=\frac{1}{2^4}=P(Y=-4)$

$E(Y^4)=2^4 \frac{4}{2^4}+(-2)^4 \frac{4}{2^4}+4^4 \frac{1}{2^4}+(-4)^4 \frac{1}{2^4}=4+4+16+16=40$

Is it correct?

• I presume the power is applied before the expectation? – Denziloe Aug 25 '18 at 16:30
• What specific part of the solution do you want help with? Please note that we don't field yes/no questions here: we're looking for more substance than that. – whuber Aug 25 '18 at 17:53

When in doubt I like to double check my work by running a simulation with Python. I sampled uniformly from the two possible values of -1 and 1 and created an array with $10^7$ rows and 4 columns.

array([[-1, -1,  1,  1],
[ 1, -1, -1,  1],
[-1, -1,  1, -1],
...,
[ 1,  1,  1, -1],
[ 1,  1,  1, -1],
[ 1,  1,  1,  1]])

The columns represent the $X_i$ values for a random trial and the sum of each row represents the $Y$ variables. Raising the sum of each row to the fourth power and then taking the mean yields a value that is approximately 40.

import numpy as np

possible_values = (-1, 1)
n_trials = 10**7
Xi_values = np.random.choice(possible_values, size=n_trials*4).reshape(n_trials, 4)
Y_values = np.sum(Xi_values, axis=1)
np.mean(Y_values**4)
40.0041056