How Do We Find the Expectation and Variance for a Continuous Random Variable?
For a continuous random variable, we calculate expected values using the same basic idea as in the discrete case. The difference is that we replace the pmf with the pdf, and the sum with an integral.
Recall that if $X$ is discrete, its expected value is
$$\mathbb{E}(X)=\sum_x x \ \mathbb{P}(X=x).$$
Here, each possible value $x$ is weighted by its probability $\mathbb{P}(X=x)$, given by the probability mass function.
If $X$ is continuous, this approach will not work directly. We cannot list all its possible values, and the probability of any one particular value is zero:
$$\mathbb{P}(X=x)=0.$$
Instead of a sum weighted by the pmf, we use an integral weighted by the pdf. If $f_X(x)$ is the probability density function of $X$, then
$$\mathbb{E}(X)=\int_{-\infty}^{\infty} x \ f_X(x) dx.$$
The basic intuition is unchanged. Values of $X$ are still being weighted according to how likely the random variable is to lie around them; the pdf now provides these weights.
If $f_X(x)=0$ outside a particular range, we can of course ignore those parts of the integral.
As before, sometimes the integral might not converge, and so the expectation doesn’t exist – but we won’t be concerned with these cases.
The variance of a continuous random variable is defined in exactly the same way as before:
$$\operatorname{Var}(X)=\mathbb{E}\left((X-\mathbb{E}(X))^2\right).$$
We can also use the equivalent formula
$$\operatorname{Var}(X)=\mathbb{E}(X^2)-\left(\mathbb{E}(X)\right)^2.$$
To calculate $\mathbb{E}(X^2)$, we use the same integral as for $\mathbb{E}(X)$, but replace $x$ with $x^2$:
$$\mathbb{E}(X^2)=\int_{-\infty}^{\infty} x^2 f_X(x) dx.$$
More generally, where the integral exists, we can find the expectation of a function $g(X)$ in the same way:
$$\mathbb{E}(g(X))=\int_{-\infty}^{\infty} g(x)f_X(x) dx.$$
Finally, the standard deviation is again the square root of the variance:
$$\operatorname{SD}(X)=\sqrt{\operatorname{Var}(X)}.$$
So, the move from discrete to continuous random variables is quite natural: only the pmf becomes a pdf, and probability-weighted sums become density-weighted integrals. Everything else remains unchanged.
Background:
Understanding Econometrics is completely free to use, and always will be.
If you found the site useful and would like to help me keep adding new material, please consider buying me a coffee! Buy me a coffee ☕