This was the 2nd problem from the HW, to use the moment generating function to derive the expected value and variance for the binomial distribution.

Moment generating function (MGF) for a random variable X:

\[ M_X(t) = E[e^{tX}] \]

For a binomial distribution, the probability mass function (PMF) is

\[ P(X = k) = \binom{n}{k} p^k (1-p)^{n-k} \]

You can use it to derive the MGF specific to the binomial distribution.

\[ M_X(t) = E[e^{tX}] \]

\[ e^{tX} = \sum_{k=0}^{n} e^{tk} P(X = k) \]

Substitute

\[ M_X(t) = E\left[\sum_{k=0}^{n} e^{tk} P(X = k)\right] \] \[ = \sum_{k=0}^{n} e^{tk} P(X = k) \]

\[ M_X(t) = \sum_{k=0}^{n} e^{tk} \binom{n}{k} p^k (1-p)^{n-k} \]

\[ M_X(t) = (1 - p + pe^t)^n \]

You can use this to derive the expected value for the binomial distribution.

Expected Value

We have to differentiate the MGF wrt to t and evaluate at t=0.

When you differentiate you get: \[ n(1 - p + pe^t)^{n-1} \cdot p \cdot e^t \]

Then when you evaluate at \(t = 0\): \[ \text{Expected Value} = n \cdot p \]

Variance

Now you need to differentiate the MGF twice and evaluate at \(t = 0\). Then you have to subtract the square of the first derivative evaluated at \(t = 0\):

Differentiate twice to get: \[ n(n-1)(1 - p + pe^t)^{n-2} \cdot p^2 \cdot e^{2t} + n(1 - p + pe^t)^{n-1} \cdot p \cdot e^t \]

Evaluating at \(t = 0\): \[ \text{Variance} = n(n-1)p^2 + np - (np)^2 \]

\[ \text{Variance} = np(n-1)p + np - np(n+p) \]

\[ \text{Variance} = np(1-p) \]